[gccsdk] [Bug 222] New: exec() functions and single/double quotes in arguments

bugzilla-daemon at riscos.info bugzilla-daemon at riscos.info
Wed Sep 7 08:28:43 PDT 2011


http://www.riscos.info/bugzilla3/show_bug.cgi?id=222

           Summary: exec() functions and single/double quotes in arguments
           Product: GCC/GCCSDK
           Version: other
          Platform: Other
        OS/Version: RISC OS
            Status: NEW
          Severity: normal
          Priority: P1
         Component: C compiler
        AssignedTo: John.Tytgat at aaug.net
        ReportedBy: duncan_moore at ntlworld.com
   Estimated Hours: 0.0


The exec() functions automatically backslash single and double quotes in
arguments, which makes it impossible to pass them into RISC OS commands without
getting them automatically backslashed. On the other hand, system() works OK
with RISC OS commands with quotes, because they are not automatically
backslashed.
For example, the program below gives this output:

system: Echo " prints "
exec  : Echo " prints \"

This make it impossible to directly use RISC OS commands requiring single or
double quotes with programs like GNU 'make'.

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>

static int ro_exec(char* const cmd[]) {
  int retval,status;
  pid_t childpid=fork();
  if (childpid==0) {
    retval=execvp(cmd[0],cmd);
    return retval;
  }
  else if (childpid>0) {
    wait(&status);
    return WEXITSTATUS(status);
  } else {
    printf("fork() error\n");
    exit(1);
  }
}

int main(void) {
  const char* cmds="Echo \"";
  printf("system: %s prints ",cmds);
  fflush(stdout);
  system(cmds);

  char* cmde[3];
  cmde[0]=strdup("Echo");
  cmde[1]=strdup("\"");
  cmde[2]=0;
  printf("exec  : %s %s prints ",cmde[0],cmde[1]);
  fflush(stdout);
  ro_exec(cmde);

  return 0;
}

-- 
Configure bugmail: http://www.riscos.info/bugzilla3/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.




More information about the gcc mailing list