Re: Absolute paths



Michael ROGERS wrote:

> >There are two ways to do it:
> > - use the path that was given to configure at compile time
> > - allow the user to set an environment variable or edit a 
> >   config file setting a new path
> 
> Doesn't argv[0] give you the full pathname of the executable image of your 
> application?

No, it gives what was passed in argv argument to execve(). 

SYNOPSIS

#include <unistd.h>

int execve(const char *path, char *const argv[], char *const envp[]);

Path is the first argument. argv[0] within the application is whatever
was passed as a second argument to execve(). They don't have to be the
same and they are very often not the same. The most common example
is shell giving `/usr/bin/ls' as a first argument, but only `ls' as
argv[0].

-- 
 .-.   .-.    I don't work for my employer.
(_  \ /  _)
     |        dave@srce.hr
     |        dave@fly.srk.fer.hr





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]