Bruno Haible wrote:
Paul Eggert wrote:

"Peter O'Gorman" <[EMAIL PROTECTED]> writes:

getprogname(3), if it exists, can be used as well as other
alternatives (e.g. argv[0]).

Thanks, I wasn't aware of the BSD getprogname until now.


Me too.


How about this proposal?

* Change the progname module to use the BSD getprogname naming
 convention.  No sense reinventing the wheel.  That way, programs can
 simply use the system-defined functions on BSD.

* Rewrite the other gnulib code to use the new convention.

* Ask gnulib users to switch to the new convention.


Yes, that's the most sensible thing to do. If there are no objections,
I will change the 'progname' module accordingly.
[libtool list cut]

Solaris seems to have a getexecname, so between, getprogname, getexecname and program_invocation_short_name, BSD, solaris and glibc using OSes are covered. I'd suggest the following instead of Paul's proposal, as it allows the programmer to override the program name. Given that though, Paul's proposal is better than current.

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;
}


_______________________________________________
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib

Reply via email to