This is a somewhat lame point, but you can't always trust argv[0] to not be NULL.
I've got two programs - 'b' that prints out if the first argv is NULL, and 'a' that calls it with no command line args.
Here's the code for 'b.c'
Code:
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("%i args\n",argc);
if(argv[0] == NULL) {
printf("argv[0] is NULL\n");
}
return 0;
}
Here's the code for 'a.c', that execs 'b' without ANY command line args:
Code:
#include <stdio.h>
#include <unistd.h>
char * const args[] = {
NULL
};
char *env[] = {
NULL
};
int main(int argc, char *argv[]) {
execve("./b", args, env);
fprintf(stderr, "Exec failed\n");
return 0;
}