From add053d4e6be3a46609490b98aa5976dd3d669e3 Mon Sep 17 00:00:00 2001
From: Peter S. Mazinger <ps.m@gmx.net>
Date: Thu, 14 Apr 2011 15:30:22 +0200
Subject: [PATCH 246/396] make UCLIBC_HAS_PROGRAM_INVOCATION_NAME and UCLIBC_HAS___PROGNAME independent options

Signed-off-by: Peter S. Mazinger <ps.m@gmx.net>
---
 extra/Configs/Config.in             |    1 -
 include/errno.h                     |    3 +++
 libc/misc/internals/__uClibc_main.c |   31 ++++++++++++++++++-------------
 utils/getconf.c                     |    6 ++----
 4 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index 6d5b561..33819e3 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -745,7 +745,6 @@ config UCLIBC_HAS_PROGRAM_INVOCATION_NAME
 config UCLIBC_HAS___PROGNAME
 	bool "Support for __progname"
 	default y
-	depends on UCLIBC_HAS_PROGRAM_INVOCATION_NAME
 	help
 	  Some packages (like openssh) like to peek into internal libc
 	  symbols to make their output a bit more user friendly.
diff --git a/include/errno.h b/include/errno.h
index 7e1f583..5340601 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -47,6 +47,9 @@ __BEGIN_DECLS
 extern int errno;
 #endif
 
+#ifdef _LIBC
+extern const char *__progname, __progname_full;
+#endif
 #if defined __USE_GNU && defined __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
 
 /* The full and simple forms of the name with which the program was
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index 95de892..cdccbed 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -144,14 +144,19 @@ extern void (*__fini_array_end []) (void) attribute_hidden;
 extern unsigned long _dl_skip_args;
 #endif
 
-attribute_hidden const char *__uclibc_progname = "";
-#ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
-const char *program_invocation_short_name = "";
-const char *program_invocation_name = "";
+const char *__uclibc_progname = "";
+#if !defined __UCLIBC_HAS___PROGNAME__ && defined __USE_GNU && defined __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
+# define __progname program_invocation_short_name
+# define __progname_full program_invocation_name
 #endif
-#ifdef __UCLIBC_HAS___PROGNAME__
-weak_alias (program_invocation_short_name, __progname)
-weak_alias (program_invocation_name, __progname_full)
+#if defined __UCLIBC_HAS___PROGNAME__ || (defined __USE_GNU && defined __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__)
+const char *__progname = "";
+/* psm: why have a visible __progname_full? */
+const char *__progname_full = "";
+# if defined __UCLIBC_HAS___PROGNAME__ && defined __USE_GNU && defined __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
+weak_alias (__progname, program_invocation_short_name)
+weak_alias (__progname_full, program_invocation_name)
+# endif
 #endif
 
 /*
@@ -396,14 +401,14 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
 #endif
 
     __uclibc_progname = *argv;
-#ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
+#if defined __UCLIBC_HAS___PROGNAME__ || (defined __USE_GNU && defined __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__)
     if (*argv != NULL) {
-	program_invocation_name = *argv;
-	program_invocation_short_name = strrchr(*argv, '/');
-	if (program_invocation_short_name != NULL)
-	    ++program_invocation_short_name;
+	__progname_full = *argv;
+	__progname = strrchr(*argv, '/');
+	if (__progname != NULL)
+	    ++__progname;
 	else
-	    program_invocation_short_name = program_invocation_name;
+	    __progname = *argv;
     }
 #endif
 
diff --git a/utils/getconf.c b/utils/getconf.c
index 8addf31..90fcb67 100644
--- a/utils/getconf.c
+++ b/utils/getconf.c
@@ -1055,10 +1055,8 @@ static const struct { const char *name; int num; } specs[] =
   };
 static const int nspecs = sizeof (specs) / sizeof (specs[0]);
 
-#ifdef __UCLIBC_HAS___PROGNAME__
-extern const char *__progname;
-#else
-#define __progname "foo"
+#ifndef __UCLIBC_HAS___PROGNAME__
+static const char *__progname = "getconf"
 #endif
 
 static attribute_noreturn void
-- 
1.7.0.4

