diff options
author | Andrew Shadura <andrewsh@debian.org> | 2014-09-14 17:41:43 +0200 |
---|---|---|
committer | Andrew Shadura <andrew@shadura.me> | 2015-07-25 14:44:57 +0200 |
commit | 02e4dec7376d8e7b563b8008b979682b82b23e11 (patch) | |
tree | 18b1263e3a507d785fbde6a8a09e6e019ff986a8 /features/progname/progname.c | |
parent | 99305952b2affb1672b6f44834378729c753aab4 (diff) | |
parent | 7bea690e43ee009efc9e8f6a45504496348cd3ee (diff) |
Imported Debian patch 0.28.0-1
Diffstat (limited to 'features/progname/progname.c')
-rw-r--r-- | features/progname/progname.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/features/progname/progname.c b/features/progname/progname.c new file mode 100644 index 0000000..c025cfe --- /dev/null +++ b/features/progname/progname.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014 by Aleksey Cheusov + * See LICENSE file in the distribution. + */ + +#include <string.h> +#include <stdlib.h> +#include <errno.h> + +#include <mkc_progname.h> + +static const char *__prog = NULL; + +const char * getprogname (void) +{ + if (__prog) + return __prog; + +#ifdef HAVE_FUNC0_GETEXECNAME_STDLIB_H + /* SunOS */ + setprogname (getexecname ()); + return getprogname (); +#elif defined(HAVE_VAR_PROGRAM_INVOCATION_SHORT_NAME_ERRNO_H) + return program_invocation_short_name; +#else + return "<unset_progname>"; +#endif +} + +void setprogname (const char *progname) +{ + const char *s = strrchr (progname, '/'); + __prog = progname; + + if (s) + __prog = s + 1; +} |