Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps
Newsgroups: comp.lang.c
From: flaps@dgp.toronto.edu (Alan J Rosenthal)
Subject: Re: Contents of argv[0]
Message-ID: <1989Aug19.184215.1274@jarvis.csri.toronto.edu>
References: <9002@attctc.Dallas.TX.US> <1017@virtech.UUCP> <10094@csli.Stanford.EDU> <1935@ifi.uio.no> <10148@csli.Stanford.EDU>
Date: 19 Aug 89 22:42:15 GMT

gisle@ifi.uio.no (Gisle Hannemyr) writes:
>Is there anything that can be relied upon for [indicating where the executable
>file resides]?

poser@csli.Stanford.EDU (Bill Poser) writes, explaining how a shellscript
wrapper can accomplish this:
>	which $0 > .L3_loc

This will not work in all cases!  There is no way to tell where the executable
resides.

Using "which $0" will FAIL if the program is invoked with an argv[0] which the
user could not have typed to access that program.  For example:
	execl("/my/strange/directory/prog", "prog", (char *)NULL);

An example which happens to you every day is the initial execution of your
login shell, which is run with an argv[0] beginning with a minus sign to let it
know that it's a login shell.

ajr