- if (strpbrk(prog->argv[argc_l - 1],"*[]?")!= NULL){
- rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->glob_result);
- if (rc == GLOB_NOSPACE) {
- error_msg("out of space during glob operation\n");
- return;
- } else if (rc == GLOB_NOMATCH ||
- (!rc && (prog->glob_result.gl_pathc - i) == 1 &&
- strcmp(prog->argv[argc_l - 1],
- prog->glob_result.gl_pathv[i]) == 0)) {
- /* we need to remove whatever \ quoting is still present */
- src = dst = prog->argv[argc_l - 1];
- while (*src) {
- if (*src == '\\') {
- src++;
- *dst++ = process_escape_sequence(&src);
- } else {
- *dst++ = *src;
- src++;
+ /* Ok. They don't have a recent glibc and they don't have uClibc. Chances
+ * are about 100% they don't have wordexp(). So instead the best we can do
+ * is use glob and then fixup environment variables and such ourselves.
+ * This is better then nothing, but certainly not perfect */
+
+ /* It turns out that glob is very stupid. We have to feed it one word at a
+ * time since it can't cope with a full string. Here we convert command
+ * (char*) into cmd (char**, one word per string) */
+ {
+
+ int flags = GLOB_NOCHECK
+#ifdef GLOB_BRACE
+ | GLOB_BRACE
+#endif
+#ifdef GLOB_TILDE
+ | GLOB_TILDE
+#endif
+ ;
+ char *tmpcmd, *cmd, *cmd_copy;
+ /* We need a clean copy, so strsep can mess up the copy while
+ * we write stuff into the original (in a minute) */
+ cmd = cmd_copy = strdup(command);
+ *command = '\0';
+ for (index = 0, tmpcmd = cmd;
+ (tmpcmd = strsep_space(cmd, &index)) != NULL; cmd += index, index=0) {
+ if (*tmpcmd == '\0')
+ break;
+ retval = glob(tmpcmd, flags, NULL, &expand_result);
+ free(tmpcmd); /* Free mem allocated by strsep_space */
+ if (retval == GLOB_NOSPACE) {
+ /* Mem may have been allocated... */
+ globfree (&expand_result);
+ error_msg(out_of_space);
+ return FALSE;
+ } else if (retval != 0) {
+ /* Some other error. GLOB_NOMATCH shouldn't
+ * happen because of the GLOB_NOCHECK flag in
+ * the glob call. */
+ error_msg("syntax error");
+ return FALSE;
+ } else {
+ /* Convert from char** (one word per string) to a simple char*,
+ * but don't overflow command which is BUFSIZ in length */
+ for (i=0; i < expand_result.gl_pathc; i++) {
+ length=strlen(expand_result.gl_pathv[i]);
+ if (total_length+length+1 >= BUFSIZ) {
+ error_msg(out_of_space);
+ return FALSE;
+ }
+ if (i>0) {
+ strcat(command+total_length, " ");
+ total_length+=1;
+ }
+ strcat(command+total_length, expand_result.gl_pathv[i]);
+ total_length+=length;