Contents of argv[0]

Conor P. Cahill cpcahil at virtech.UUCP
Tue Aug 15 21:55:39 AEST 1989


In article <9002 at attctc.Dallas.TX.US>, jls at attctc.Dallas.TX.US (Jerome Schneider) writes:
> Both K&R and H&S document the argv[0] string as "the name of the program".
> This definition doesn't seem to mandate (or exclude) the presence of a path
> component in the string.  A few  *nix programs use rindex() or strrchr() to
> scan for '/', implying (to me at least) that _some_ implementations consider
> "name" to include such information.

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.



More information about the Comp.lang.c mailing list