From 96b3c930fe53eb1dbfc42cf5d0723df02bdda815 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 15 Feb 2013 03:57:12 +0000 Subject: Use _splitpath; _splitpath_s isn't really available git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1839 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libpm.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'lib/libpm.c') diff --git a/lib/libpm.c b/lib/libpm.c index 6bc8521c..61a47099 100644 --- a/lib/libpm.c +++ b/lib/libpm.c @@ -708,18 +708,6 @@ extractAfterLastSlash(const char * const fullPath, -#if MSVCRT -static void -splitpath(const char * const fullPath, - char * const retval, - size_t const retvalSize) { - - _splitpath_s(fullPath, 0, 0, 0, 0, retval, retvalSize, 0, 0); -} -#endif - - - char * pm_arg0toprogname(const char arg0[]) { /*---------------------------------------------------------------------------- @@ -736,14 +724,23 @@ pm_arg0toprogname(const char arg0[]) { The return value is in static storage within. It is NUL-terminated, but truncated at 64 characters. -----------------------------------------------------------------------------*/ - static char retval[64+1]; +#define MAX_RETVAL_SIZE 64 #if MSVCRT - splitpath(arg0, retval, sizeof(retval)); + /* Note that there exists _splitpath_s, which takes a size argument, + but it is only in "secure" extensions of MSVCRT that come only with + MSVC; but _splitpath() comes with Windows. MinGW has a header file + for it. + */ + static char retval[_MAX_FNAME]; + _splitpath(fullPath, 0, 0, retval, 0); + if (MAX_RETVAL_SIZE < _MAX_FNAME) + retval[MAX_RETVAL_SIZE] = '\0'; #else + static char retval[MAX_RETVAL_SIZE+1]; extractAfterLastSlash(arg0, retval, sizeof(retval)); #endif - return(retval); + return retval; } -- cgit 1.4.1