Subject: lib/10675: __progname is not declared
To: None <gnats-bugs@gnats.netbsd.org>
From: Johan Danielsson <joda@pdc.kth.se>
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
>Closed-Date:
>Last-Modified:
>Originator: Johan Danielsson
>Release: *
>Organization:
>Environment:
<machine, os, target, libraries (multiple lines)>
System: NetBSD blubb.pdc.kth.se 1.5B NetBSD 1.5B (BLUBB) #247: Mon Jul 10 13:56:19 CEST 2000 joda@blubb.pdc.kth.se:/usr/misc/src/netbsd/netbsd-cvs/src/sys/arch/i386/compile/BLUBB i386
>Description:
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);
and
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
calling
set_progname(argv[0]);
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.
>How-To-Repeat:
Code inspection.
>Fix:
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD$");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
extern char *__progname; /* Program name, from crt0. */
const char *
get_progname(void)
{
return __progname;
}
void
set_progname(const char *progname)
{
/* do nothing */
}
>Release-Note:
>Audit-Trail:
>Unformatted: