From 8f04046f56075bde720663428a913b7dbe2b8f6f Mon Sep 17 00:00:00 2001 From: Jamey Sharp
Date: Sun, 24 Dec 2006 01:00:56 -0800 Subject: [PATCH] Use \ as the path separator in _basename on Windows, and strip ".exe" from argv[0] before checking for program name. Commit by Josh Triplett and Jamey Sharp. --- missFuncs.c | 17 +++++++++++++++-- mtools.c | 5 ++++- sysincludes.h | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/missFuncs.c b/missFuncs.c index c693412..50e2253 100644 --- a/missFuncs.c +++ b/missFuncs.c @@ -370,12 +370,18 @@ void myexit(int code) #endif +#ifdef OS_mingw32msvc +static const char PATH_SEP = '\\'; +#else +static const char PATH_SEP = '/'; +#endif + /*#ifndef HAVE_BASENAME*/ const char *_basename(const char *filename) { char *ptr; - ptr = strrchr(filename, '/'); + ptr = strrchr(filename, PATH_SEP); if(ptr) return ptr+1; else @@ -383,4 +389,11 @@ const char *_basename(const char *filename) } /*#endif*/ - +/* Strip the suffix ".exe" from the argument, if present. */ +void _stripexe(char *filename) +{ + char *ptr; + ptr = strrchr(filename, '.'); + if(ptr && !strcasecmp(ptr, ".exe")) + *ptr = '\0'; +} diff --git a/mtools.c b/mtools.c index 7d9368e..7054443 100644 --- a/mtools.c +++ b/mtools.c @@ -94,7 +94,10 @@ int main(int argc,char **argv) #ifdef __EMX__ argv[0] = _getname(argv[0]); _remext(argv[0]); name = argv[0]; -#else +#else +#ifdef OS_mingw32msvc + _stripexe(argv[0]); +#endif name = _basename(argv[0]); #endif progname = argv[0]; diff --git a/sysincludes.h b/sysincludes.h index d414b5d..d4c48cc 100644 --- a/sysincludes.h +++ b/sysincludes.h @@ -410,6 +410,8 @@ const char *basename(const char *filename); const char *_basename(const char *filename); +void _stripexe(char *filename); + #ifndef __STDC__ # ifndef signed # define signed /**/ -- 1.4.4.2