[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getprogname
From: |
Bruno Haible |
Subject: |
Re: getprogname |
Date: |
Tue, 10 Jan 2006 15:50:14 +0100 |
User-agent: |
KMail/1.5 |
Peter O'Gorman wrote:
> Solaris seems to have a getexecname
Interesting. So this provides a fallback, like on glibc systems, for the
case when setprogname(argv[0]) has not been called.
> I'd suggest the following instead of Paul's proposal, as it allows
> the programmer to override the program name.
Well, Paul's proposal to use 'get/setprogname' also allows the
programmer to override the program name.
> static char * prog_name = NULL;
>
> void
> set_prog_name(char * name)
> {
> if (prog_name) free(prog_name);
> prog_name = strdup(name);
> }
>
> char *
> get_prog_name(void)
> {
> char * name;
> if (prog_name)
> name = prog_name;
> else
> {
> #if defined(HAVE_GETPROGNAME)
> #include <stdlib.h>
> name = getprogname();
> #elif defined(HAVE_GETEXECNAME)
> #include <stdlib.h>
> name = getexecname();
> #elif defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME)
> #include <errno.h>
> name = program_invocation_short_name;
> #else
> name = "executable";
> #endif
> }
> return name;
> }
Well, my intention is basically this:
#if !(HAVE_GETPROGNAME && HAVE_SETPROGNAME) /* nothing to do on FreeBSD, NetBSD
*/
static const char * progname = NULL;
void
setprogname(const char *arg)
{
progname = arg;
}
const char *
getprogname()
{
if (progname != NULL)
/* actually not only basename, but also remove leading "-" and ".lt-" */
return basename (progname);
else
{
#if HAVE_PROGRAM_INVOCATION_SHORT_NAME /* glibc */
return program_invocation_short_name;
#elif HAVE_GETEXECNAME /* Solaris */
return basename (getexecname ());
#else
return NULL;
#endif
}
}
#endif
Bruno
- Re: use of program_name, (continued)
- Re: use of program_name, Dave Love, 2006/01/06
- Re: [bug-gnulib] Re: use of program_name, Bruno Haible, 2006/01/09
- use of -fno-common on Darwin (was: use of program_name), Ralf Wildenhues, 2006/01/09
- Re: use of -fno-common on Darwin, Peter O'Gorman, 2006/01/09
- Re: use of -fno-common on Darwin, Paul Eggert, 2006/01/09
- Re: use of -fno-common on Darwin, Bob Friesenhahn, 2006/01/10
- Re: use of -fno-common on Darwin, Bruno Haible, 2006/01/10
- Re: use of -fno-common on Darwin, Peter O'Gorman, 2006/01/10
- Re: getprogname,
Bruno Haible <=
- Re: getprogname, Paul Eggert, 2006/01/10
- Re: getprogname, Bruno Haible, 2006/01/10
- Re: getprogname, Paul Eggert, 2006/01/11
- Re: use of -fno-common on Darwin, James Youngman, 2006/01/10
- Re: getprogname, Bruno Haible, 2006/01/11
- Re: getprogname, Paul Eggert, 2006/01/11
- Re: [bug-gnulib] Re: use of program_name, Bruno Haible, 2006/01/09
- Re: use of program_name, James Youngman, 2006/01/05
- Re: [bug-gnulib] Re: use of program_name, Bruno Haible, 2006/01/09
- Re: [bug-gnulib] Re: use of program_name, James Youngman, 2006/01/09