How does a program get its path name?

Roberto Shironoshita shirono at grasp.cis.upenn.edu
Mon Feb 22 16:07:27 AEST 1988


In article <2933 at sdsu.UUCP> turtle at sdsu.UCSD.EDU (Andrew Scherpbier) writes:
> [Leisner.Henr at xerox.com's original article, <11923 at brl-adm.ARPA>,]
> [asking how cc knows to look at /lib for the passes              ]
>
> When a program executes, the full path to the executable file is
> kept in the zero-th argument.

I'm sorry, but this is plain and simply an overstatement.  It may be
right if the command was the full path, but not necessarily otherwise.

> If you have a declaration of main which looks like this:
>	main(argc,argv)
>	int	argc;
>	char	*argv[];
>
> then argv[0] is a pointer to the full path.

argv[0] contains whatever was passed as argv[0] to the exec family of
system calls.  According to AT&T's manual for SVR2 (of 04/84), the
convention is that it be either the full pathname or its last
component.  The behavior I've seen on both /bin/csh and /bin/sh under
Ultrix 2.0 and HCX/UX 3.0 (with universe both bsd and att) is that it
is whatever came as the command.  If you specify "cc" as your command,
strcmp (argv[0], "cc") == 0.

Thus, you can't say that argv[0] IS a pointer to the full path.  You
can't even say that it isn't (sigh!).

                                   Roberto Shironoshita

-------------------------------------------------------------------------
@@@@@@@@@\   Disclaimers:
 @@     @@   1 -  The opinions expressed here are my own.  The University
 @@     @@        need not share them, or even be aware of them.
 @@@@@@@@/   2 -  Like most humans, I'm bound to err at times.  I believe
 @@               what I have said, but agree that I may be wrong.
 @@
@@@@         Internet: shirono at grasp.cis.upenn.edu



More information about the Comp.unix.questions mailing list