Contents of argv[0]
Oliver Laumann
net at tub.UUCP
Wed Aug 16 22:46:47 AEST 1989
In article <1017 at virtech.UUCP> cpcahil at virtech.UUCP (Conor P. Cahill) writes:
> On most, if not all, unix systems argv[0] will contain the path used to
> execute the program (i.e. the first argument to an execl()). This may be
> a relative path, a full path and/or a simple name. Your code should handle
> all cases.
You should also anticipate the case that argv[0] is not there (i.e. argc
is zero). It is perfectly valid to execute a program like this:
execl (your_program, (char *)0);
The manual only says that ``by convention'' at least one argument must
be passed to the program. However, this is not enforced. For a good
laugh compile the following program:
main (ac, av) char **av; {
execl (av[1], (char *)0);
perror ("exec");
}
and then try, for instance,
% a.out /bin/ls
% a.out /usr/ucb/mail
% a.out /bin/csh
% a.out /usr/ucb/vi
% a.out /bin/size
Regards,
--
Oliver Laumann net at TUB.BITNET net at tub.UUCP
More information about the Comp.lang.c
mailing list