diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/err.c | 15 | ||||
-rw-r--r-- | lib/libc/gen/getlogin.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/getprogname.c | 8 | ||||
-rw-r--r-- | lib/libc/gen/setproctitle.c | 7 | ||||
-rw-r--r-- | lib/libc/gen/setprogname.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/syslog.c | 6 | ||||
-rw-r--r-- | lib/libc/gmon/gmon.c | 11 | ||||
-rw-r--r-- | lib/libc/include/libc_private.h | 6 | ||||
-rw-r--r-- | lib/libc/include/namespace.h | 1 | ||||
-rw-r--r-- | lib/libc/include/un-namespace.h | 1 | ||||
-rw-r--r-- | lib/libc/locale/collate.c | 5 | ||||
-rw-r--r-- | lib/libc/stdlib/getopt.c | 11 | ||||
-rw-r--r-- | lib/libc/stdlib/malloc.c | 6 |
13 files changed, 49 insertions, 32 deletions
diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c index e3a5142..9365d7d 100644 --- a/lib/libc/gen/err.c +++ b/lib/libc/gen/err.c @@ -39,15 +39,14 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <err.h> -#include "un-namespace.h" #include <errno.h> +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "un-namespace.h" -#include <stdarg.h> - -extern char *__progname; /* Program name, from crt0. */ +#include "libc_private.h" static FILE *err_file; /* file to use for error output */ static void (*err_exit)(int); @@ -110,7 +109,7 @@ verrc(eval, code, fmt, ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -138,7 +137,7 @@ verrx(eval, fmt, ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); @@ -183,7 +182,7 @@ vwarnc(code, fmt, ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -207,7 +206,7 @@ vwarnx(fmt, ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); diff --git a/lib/libc/gen/getlogin.c b/lib/libc/gen/getlogin.c index ea895ba..664f208 100644 --- a/lib/libc/gen/getlogin.c +++ b/lib/libc/gen/getlogin.c @@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$"); #include <pthread.h> #include "un-namespace.h" -#include <libc_private.h> +#include "libc_private.h" #define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&logname_mutex) #define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&logname_mutex) diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c index b0a8dec..fd51d13 100644 --- a/lib/libc/gen/getprogname.c +++ b/lib/libc/gen/getprogname.c @@ -1,12 +1,16 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "namespace.h" #include <stdlib.h> +#include "un-namespace.h" -extern const char *__progname; +#include "libc_private.h" + +__weak_reference(_getprogname, getprogname); const char * -getprogname(void) +_getprogname(void) { return (__progname); diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c index b9b8418..d6101e1 100644 --- a/lib/libc/gen/setproctitle.c +++ b/lib/libc/gen/setproctitle.c @@ -18,6 +18,7 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "namespace.h" #include <sys/types.h> #include <sys/param.h> #include <sys/exec.h> @@ -31,6 +32,9 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <stdlib.h> #include <unistd.h> +#include "un-namespace.h" + +#include "libc_private.h" /* * Older FreeBSD 2.0, 2.1 and 2.2 had different ps_strings structures and @@ -53,7 +57,6 @@ struct old_ps_strings { #include <stdarg.h> #define SPT_BUFSIZE 2048 /* from other parts of sendmail */ -extern char * __progname; /* is this defined in a .h anywhere? */ void setproctitle(const char *fmt, ...) @@ -83,7 +86,7 @@ setproctitle(const char *fmt, ...) len = 0; } else { /* print program name heading for grep */ - (void) snprintf(buf, sizeof(buf), "%s: ", __progname); + (void)snprintf(buf, sizeof(buf), "%s: ", _getprogname()); len = strlen(buf); } diff --git a/lib/libc/gen/setprogname.c b/lib/libc/gen/setprogname.c index 5be00fa..29a6cd0 100644 --- a/lib/libc/gen/setprogname.c +++ b/lib/libc/gen/setprogname.c @@ -4,7 +4,7 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> -extern const char *__progname; +#include "libc_private.h" void setprogname(const char *progname) diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 11ae5b5..621e63a 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include <fcntl.h> #include <paths.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> @@ -60,6 +61,8 @@ __FBSDID("$FreeBSD$"); #endif #include "un-namespace.h" +#include "libc_private.h" + static int LogFile = -1; /* fd for log */ static int connected; /* have done connect */ static int opened; /* have done openlog() */ @@ -67,7 +70,6 @@ static int LogStat = 0; /* status bits, set by openlog() */ static const char *LogTag = NULL; /* string to tag the entry with */ static int LogFacility = LOG_USER; /* default facility code */ static int LogMask = 0xff; /* mask of priorities to be logged */ -extern char *__progname; /* Program name, from crt0. */ static void disconnectlog(void); /* disconnect from syslogd */ static void connectlog(void); /* (re)connect to syslogd */ @@ -181,7 +183,7 @@ vsyslog(pri, fmt, ap) stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left); } if (LogTag == NULL) - LogTag = __progname; + LogTag = _getprogname(); if (LogTag != NULL) (void)fprintf(fp, "%s", LogTag); if (LogStat & LOG_PID) diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c index be373b0..49326e5 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -43,23 +43,22 @@ __FBSDID("$FreeBSD$"); #include <sys/gmon.h> #include <sys/sysctl.h> -#include "namespace.h" #include <err.h> -#include "un-namespace.h" -#include <stdio.h> #include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" + #if defined(__ELF__) && (defined(i386) || defined(__sparc64__)) extern char *minbrk asm (".minbrk"); #else extern char *minbrk asm ("minbrk"); #endif -extern char *__progname; - struct gmonparam _gmonparam = { GMON_PROF_OFF }; static int s_scale; @@ -175,7 +174,7 @@ _mcleanup() } moncontrol(0); - snprintf(outname, sizeof(outname), "%s.gmon", __progname); + snprintf(outname, sizeof(outname), "%s.gmon", _getprogname()); fd = _open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666); if (fd < 0) { _warn("_mcleanup: %s", outname); diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index f356e18..e47e756 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -63,4 +63,10 @@ extern int __isthreaded; #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) +/* + * This is a pointer in the C run-time startup code. It is used + * by getprogname() and setprogname(). + */ +extern const char *__progname; + #endif /* _LIBC_PRIVATE_H_ */ diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h index 7753f98..bbd33c0 100644 --- a/lib/libc/include/namespace.h +++ b/lib/libc/include/namespace.h @@ -67,6 +67,7 @@ #define getdirentries _getdirentries #define getlogin _getlogin #define getpeername _getpeername +#define getprogname _getprogname #define getsockname _getsockname #define getsockopt _getsockopt #define ioctl _ioctl diff --git a/lib/libc/include/un-namespace.h b/lib/libc/include/un-namespace.h index 855c101..3b21900 100644 --- a/lib/libc/include/un-namespace.h +++ b/lib/libc/include/un-namespace.h @@ -52,6 +52,7 @@ #undef getdirentries #undef getlogin #undef getpeername +#undef getprogname #undef getsockname #undef getsockopt #undef ioctl diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index 347baef..6766c9e 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -41,6 +41,8 @@ __FBSDID("$FreeBSD$"); #include "collate.h" #include "setlocale.h" +#include "libc_private.h" + int __collate_load_error = 1; int __collate_substitute_nontrivial; char __collate_version[STR_LEN]; @@ -176,11 +178,10 @@ __collate_strdup(s) void __collate_err(int ex, const char *f) { - extern char *__progname; /* Program name, from crt0. */ const char *s; int serrno = errno; - s = __progname; + s = _getprogname(); _write(STDERR_FILENO, s, strlen(s)); _write(STDERR_FILENO, ": ", 2); s = f; diff --git a/lib/libc/stdlib/getopt.c b/lib/libc/stdlib/getopt.c index 0f9918d..4cad100 100644 --- a/lib/libc/stdlib/getopt.c +++ b/lib/libc/stdlib/getopt.c @@ -37,9 +37,13 @@ static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "namespace.h" #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "un-namespace.h" + +#include "libc_private.h" int opterr = 1, /* if error message should be printed */ optind = 1, /* index into parent argv vector */ @@ -61,7 +65,6 @@ getopt(nargc, nargv, ostr) char * const *nargv; const char *ostr; { - extern char *__progname; static char *place = EMSG; /* option letter processing */ char *oli; /* option letter list index */ @@ -88,8 +91,8 @@ getopt(nargc, nargv, ostr) if (!*place) ++optind; if (opterr && *ostr != ':' && optopt != BADCH) - (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, optopt); + (void)fprintf(stderr, "%s: illegal option -- %c\n", + _getprogname(), optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -107,7 +110,7 @@ getopt(nargc, nargv, ostr) if (opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, optopt); + _getprogname(), optopt); return (BADCH); } else /* white space */ diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 202ac69..43aad2d 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -297,14 +297,12 @@ wrtmessage(char *p1, char *p2, char *p3, char *p4) void (*_malloc_message)(char *p1, char *p2, char *p3, char *p4) = wrtmessage; -extern char *__progname; - static void wrterror(char *p) { suicide = 1; - _malloc_message(__progname, malloc_func, " error: ", p); + _malloc_message(_getprogname(), malloc_func, " error: ", p); abort(); } @@ -314,7 +312,7 @@ wrtwarning(char *p) if (malloc_abort) wrterror(p); - _malloc_message(__progname, malloc_func, " warning: ", p); + _malloc_message(_getprogname(), malloc_func, " warning: ", p); } /* |