Contents of argv[0]

Juergen Wagner gandalf at csli.Stanford.EDU
Wed Aug 16 04:10:43 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.  (this would also make it portable to other systems that do not
>pass in the path).  On some older versions of Microsoft C, argv[0] was always
>empty (i.e. char * 0) because that information was not available from DOS.

The first argument to aqn execl is the path name of the program to be
executed. The arguments starting with the second are what the program will
get as an argv[]. This effectively means that in general, argv[0] cannot
be treated as a reliable source for the path name! [RTFM]

You have to distinguish between features provided by UNIX (in general) and
some UNIX (in particular). The execve system call makes it quite clear that
there doesn't have to be any relation whatsoever between the pathname of the
program being invoked and the argument vector argv[]. Check the man page for
execve().

Juergen Wagner		   			gandalf at csli.stanford.edu
						 wagner at arisia.xerox.com



More information about the Comp.lang.c mailing list