Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- /*
- This version has an array instead of a string for the command
- */
- int main(int argc, char* argv[]) {
- int i;
- int ret = 0;
- int skipped = 0;
- // the new gcc args to pass
- char** gccargs;
- gccargs = (char **)malloc( sizeof(char*) * (argc+1) );
- int gccargc = 0;
- char realcmd[] = "/usr/bin/gcc.real";
- //first pass through args and copy the values if they aren't filtered out
- gccargs[0] = argv[0];
- gccargc++;
- for(i=1; i<argc; i++) {
- char* arg = argv[i];
- if( strcmp(arg, "-Werror") == 0 ) {
- printf("PM gccwrap4: skipping arg: %s\n", arg);
- skipped++;
- continue;
- }
- printf("PM gccwrap4: \"%s\"\n", arg);
- gccargs[gccargc] = arg;
- gccargc++;
- }
- //next set the next one to 0 so execv knows where to stop
- gccargs[gccargc] = 0;
- printf("PM gccwrap4: final array:\n");
- for(i=0; i<gccargc; i++) {
- printf("PM gccwrap4: %s\n", gccargs[i]);
- }
- // just for testing; must be commented out because execv does not return if it is successful, so it won't run the real command
- // printf("PM gccwrap4: final command:\n %s ", realcmd);
- // ret = execv("/bin/echo", gccargs);
- ret = execv(realcmd, gccargs);
- // execv replaces this process, and does not return if successful ... does that mean this free can never be called? does that mean there is no way to free gccargs?
- free(gccargs);
- // don't free gccargs[i] because those are just pointers to argv's values
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement