How does a program get its path name?

Chris Calabrese[rs] cjc at ulysses.homer.nj.att.com
Tue Feb 23 02:56:12 AEST 1988


In article <2933 at sdsu.UUCP>, turtle at sdsu.UUCP writes:
> 
> When a program executes, the full path to the executable file is kept in
> the zero-th argument.  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.
> Is this what you were looking for?

This is true only if the program was not found in the
current working directory, in which case argv[0] will contain
only the name of the program, not the full path.  Of course,
you can test to see if argv[0][0] != '/' and getcwd()
to find the full path name.

	Christopher Calabrese
	AT&T Bell Laboratories
	ulysses!cjc



More information about the Comp.unix.questions mailing list