Canonicalize the program name if necessary in setprogname()
This commit is contained in:
@@ -40,19 +40,52 @@ extern const char *__progname;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_SETPROGNAME
|
#ifndef HAVE_SETPROGNAME
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
setprogname(const char *argv0)
|
setprogname(const char *argv0)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifndef HAVE___PROGNAME
|
#ifndef HAVE___PROGNAME
|
||||||
|
|
||||||
const char *p;
|
const char *p;
|
||||||
if(argv0 == NULL)
|
if(argv0 == NULL)
|
||||||
return;
|
return;
|
||||||
p = strrchr(argv0, '/');
|
p = strrchr(argv0, '/');
|
||||||
|
|
||||||
|
#ifdef BACKSLASH_PATH_DELIM
|
||||||
|
{
|
||||||
|
const char * pb;
|
||||||
|
|
||||||
|
pb = strrchr((p != NULL)? p : argv0, '\\');
|
||||||
|
if (pb != NULL)
|
||||||
|
p = pb;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if(p == NULL)
|
if(p == NULL)
|
||||||
p = argv0;
|
p = argv0;
|
||||||
else
|
else
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
{
|
||||||
|
char * fn = strdup(p);
|
||||||
|
char * ext;
|
||||||
|
|
||||||
|
strlwr(fn);
|
||||||
|
ext = strrchr(fn, '.');
|
||||||
|
if (ext != NULL && !strcmp(ext, ".exe"))
|
||||||
|
*ext = '\0';
|
||||||
|
|
||||||
|
__progname = fn;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
__progname = p;
|
__progname = p;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE___PROGNAME */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_SETPROGNAME */
|
#endif /* HAVE_SETPROGNAME */
|
||||||
|
Reference in New Issue
Block a user