Path: utzoo!utgpu!water!watmath!clyde!rutgers!super.upenn.edu!grasp.cis.upenn.edu!shirono From: shirono@grasp.cis.upenn.edu (Roberto Shironoshita) Newsgroups: comp.unix.questions Subject: Re: How does a program get its path name? Summary: It doesn't Keywords: executables pathnames Message-ID: <3439@super.upenn.edu> Date: 22 Feb 88 06:07:27 GMT References: <11923@brl-adm.ARPA> <2933@sdsu.UUCP> Sender: news@super.upenn.edu Reply-To: shirono@grasp.cis.upenn.edu (Roberto Shironoshita) Organization: University of Pennsylvania (CSE dept. BSE senior) Lines: 38 In article <2933@sdsu.UUCP> turtle@sdsu.UCSD.EDU (Andrew Scherpbier) writes: > [Leisner.Henr@xerox.com's original article, <11923@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@grasp.cis.upenn.edu