[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [dev-serveez] simple c question
From: |
Martin Grabmueller |
Subject: |
Re: [dev-serveez] simple c question |
Date: |
Mon, 18 Jun 2001 19:53:57 +0200 |
> From: stefan <address@hidden>
> Date: Sat, 16 Jun 2001 02:51:55 +0200 (CEST)
>
> Hello list,
> does anyone know how can I get the executable's name at runtime without
> argv[0] ?
Portably, this is not possible, but with the GNU libc. The following
is quoted from the GNU libc Reference Manual:
- Variable: char * program_invocation_name
This variable's value is the name that was used to invoke the
program running in the current process. It is the same as
`argv[0]'. Note that this is not necessarily a useful file name;
often it contains no directory names. *Note Program Arguments::.
- Variable: char * program_invocation_short_name
This variable's value is the name that was used to invoke the
program running in the current process, with directory names
removed. (That is to say, it is the same as
`program_invocation_name' minus everything up to the last slash,
if any.)
The library initialization code sets up both of these variables
before calling `main'.
*Portability Note:* These two variables are GNU extensions. If you
want your program to work with non-GNU libraries, you must save the
value of `argv[0]' in `main', and then strip off the directory names
yourself. We added these extensions to make it possible to write
self-contained error-reporting subroutines that require no explicit
cooperation from `main'.
Regards,
'martin