Subject: lib/10675: __progname is not declared
To: None <>
From: Johan Danielsson <>
List: netbsd-bugs
Date: 07/25/2000 02:51:16
>Number:         10675
>Category:       lib
>Synopsis:       __progname is not declared
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 25 02:52:00 PDT 2000
>Originator:     Johan Danielsson
>Release:        *
	<machine, os, target, libraries (multiple lines)>
System: NetBSD 1.5B NetBSD 1.5B (BLUBB) #247: Mon Jul 10 13:56:19 CEST 2000 i386


The __progname variable is not declared in any header file, yet a
*lot* of programs are using it to get their name (I find more than 150
declarations of __progname in basesrc).

To solve this I propose that two new functions be added to libc:

        const char *get_progname(void);
        void set_progname(const char *);

The first should return the `name' of the running program (effectively
__progname), and the second should set that name.

get_progname is hopefully quite uncontroversial.

The reason for set_progname is purly for portability. Most systems
don't have a __progname equivalent, and if you want to use
get_progname() in on such a system you have to set the progname when
the application starts. The most easy way I've found to do this is by


the first thing you do in main. An implementation of set_progname can
be found in basesrc/crypto/dist/heimdal/lib/roken/warnerr.c. On
systems that already define __progname it does nothing; if this is
what it should do is open for discussion.

Code inspection.

#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#endif /* LIBC_SCCS and not lint */

#include "namespace.h"

extern char *__progname;		/* Program name, from crt0. */

const char *
    return __progname;

set_progname(const char *progname)
    /* do nothing */