mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: [PATCH] program_invocation_name
Date: Thu, 4 Apr 2013 22:51:58 -0400	[thread overview]
Message-ID: <20130405025157.GA5538@brightrain.aerifal.cx> (raw)

[-- Attachment #1: Type: text/plain, Size: 88 bytes --]

In case we want to add it, here is a patch for
program_invocation_name. Comments?

Rich

[-- Attachment #2: progname.diff --]
[-- Type: text/plain, Size: 1291 bytes --]

diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 04a454e..3ccd979 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -8,8 +8,9 @@ void __init_ldso_ctors(void);
 #define AUX_CNT 38
 
 extern size_t __hwcap, __sysinfo;
+extern const char *__progname, *__progname_full;
 
-void __init_libc(char **envp)
+void __init_libc(char **envp, char *pn)
 {
 	size_t i, *auxv, aux[AUX_CNT] = { 0 };
 	__environ = envp;
@@ -19,6 +20,11 @@ void __init_libc(char **envp)
 	__hwcap = aux[AT_HWCAP];
 	__sysinfo = aux[AT_SYSINFO];
 
+	if (pn) {
+		__progname = __progname_full = pn;
+		for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
+	}
+
 	__init_tls(aux);
 	__init_security(aux);
 }
@@ -30,7 +36,7 @@ int __libc_start_main(
 {
 	char **envp = argv+argc+1;
 
-	__init_libc(envp);
+	__init_libc(envp, argv[0]);
 
 	libc.ldso_fini = ldso_fini;
 	libc.fini = fini;
diff --git a/src/internal/libc.c b/src/internal/libc.c
index d22d274..7e05f85 100644
--- a/src/internal/libc.c
+++ b/src/internal/libc.c
@@ -16,3 +16,7 @@ __asm__(".hidden __libc");
 
 size_t __hwcap;
 size_t __sysinfo;
+const char *__progname=0, *__progname_full=0;
+
+weak_alias(__progname, program_invocation_short_name);
+weak_alias(__progname_full, program_invocation_name);

                 reply	other threads:[~2013-04-05  2:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130405025157.GA5538@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).