+ * merge command and parameters to command line
+ */
+
+static char *
+merge_command(const char *command, const char *params)
+{
+ /* allocate extra space for 2x'"', ' ' and '\0' */
+ char *cmd_line = (char *)Safe_alloc(strlen(command) + strlen(params) + 4);
+ sprintf(cmd_line, "\"%s\" %s", command, params);
+ return cmd_line;
+}
+
+
+/*!
+ * check if the path is relative or absolute (if contains the dir separator)
+ */
+
+static int
+has_path(const char *path)
+{
+ if (strrchr(path, DIR_SEPARATOR_CHAR) == NULL)
+ return 0;
+
+ return 1;
+}
+
+
+static char *
+get_path(const char *cmd)
+{
+ char *cmdLine = NULL;
+ char *command;
+ char *args;
+ char *path;
+ char cmdPath[PATH_MAX];
+
+
+ /* get the command */
+ split_command(cmd, &command, &args);
+
+ if (!has_path(command)) {
+ /* try to find the command in predefined binary paths */
+ if (NULL != (path = (char *)setFirstItem(binPathSet))) {
+ do
+ {
+ SNPRINTF(cmdPath, sizeof cmdPath,
+ "%s" DIR_SEPARATOR_STRING "%s", path, command);
+
+ /* Try if cmdPath */
+ if (0 == access(cmdPath, X_OK)) {
+ /* compose the command line */
+ cmdLine = merge_command(cmdPath, args);
+ break;
+ }
+ } while (NULL != (path = (char *)setNextItem(binPathSet)));
+ }
+ if (NULL == cmdLine)
+ cmdLine = merge_command(command, args);
+
+ Safe_free(command);
+ Safe_free(args);
+
+ return cmdLine;
+ }
+ else {
+ /*
+ * the command is defined with absolute path:
+ * just return it
+ */
+ Safe_free(command);
+ Safe_free(args);
+
+ return Safe_strdup(cmd);
+ }
+}
+#endif
+
+
+/*!
+ * call an external program with arguements
+ */