Path: utzoo!utgpu!watmath!att!ucbvax!agate!shelby!csli!gandalf From: gandalf@csli.Stanford.EDU (Juergen Wagner) Newsgroups: comp.lang.c Subject: Re: Contents of argv[0] Keywords: start-up code, argv specifications Message-ID: <10094@csli.Stanford.EDU> Date: 15 Aug 89 18:10:43 GMT References: <9002@attctc.Dallas.TX.US> <1017@virtech.UUCP> Sender: gandalf@csli.Stanford.EDU (Juergen Wagner) Reply-To: gandalf@csli.stanford.edu (Juergen Wagner) Organization: Center for the Study of Language and Information, Stanford U. Lines: 22 In article <1017@virtech.UUCP> cpcahil@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@csli.stanford.edu wagner@arisia.xerox.com