]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Initialize __progname to program_invocation_short_name
authorGuillem Jover <guillem@hadrons.org>
Fri, 25 Feb 2011 12:52:59 +0000 (13:52 +0100)
committerGuillem Jover <guillem@hadrons.org>
Sat, 14 May 2011 11:43:49 +0000 (13:43 +0200)
As we do not have cooperation from the crt0 code to set __progname, we
have to set it ourselves from getprogname() in case it's NULL. On GNU
systems we can use program_invocation_short_name which is actually set
on crt0.

src/progname.c

index ef56144d8ad3a4f5d398bec4b1e5a47db1a0d7b8..107942911a4769c4f5fa12add19ee19715f394eb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2006 Robert Millan
- * Copyright © 2010 Guillem Jover
+ * Copyright © 2010-2011 Guillem Jover
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,6 +29,7 @@
   Rejected in glibc (http://sourceware.org/ml/libc-alpha/2006-03/msg00125.html)
 */
 
+#include <errno.h>
 #include <string.h>
 
 #include <bsd/stdlib.h>
@@ -38,6 +39,11 @@ static const char *__progname = NULL;
 const char *
 getprogname(void)
 {
+#ifdef __GLIBC__
+       if (__progname == NULL)
+               __progname = program_invocation_short_name;
+#endif
+
        return __progname;
 }