/* * Copyright (c) 2014 by Aleksey Cheusov * See LICENSE file in the distribution. */ #include #include #include #include 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 ""; #endif } void setprogname (const char *progname) { const char *s = strrchr (progname, '/'); __prog = progname; if (s) __prog = s + 1; }