Contents of argv[0]
    Alan J Rosenthal 
    flaps at dgp.toronto.edu
       
    Sun Aug 20 08:42:15 AEST 1989
    
    
  
gisle at ifi.uio.no (Gisle Hannemyr) writes:
>Is there anything that can be relied upon for [indicating where the executable
>file resides]?
poser at 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
    
    
More information about the Comp.lang.c
mailing list