Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!mcvax!unido!tub!net From: net@tub.UUCP (Oliver Laumann) Newsgroups: comp.lang.c Subject: Re: Contents of argv[0] Keywords: start-up code, argv specifications Message-ID: <915@tub.UUCP> Date: 16 Aug 89 12:46:47 GMT References: <9002@attctc.Dallas.TX.US> <1017@virtech.UUCP> Reply-To: net@tub.UUCP (Oliver Laumann) Organization: Technical University of Berlin, Germany Lines: 31 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. You should also anticipate the case that argv[0] is not there (i.e. argc is zero). It is perfectly valid to execute a program like this: execl (your_program, (char *)0); The manual only says that ``by convention'' at least one argument must be passed to the program. However, this is not enforced. For a good laugh compile the following program: main (ac, av) char **av; { execl (av[1], (char *)0); perror ("exec"); } and then try, for instance, % a.out /bin/ls % a.out /usr/ucb/mail % a.out /bin/csh % a.out /usr/ucb/vi % a.out /bin/size Regards, -- Oliver Laumann net@TUB.BITNET net@tub.UUCP