about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/HISTORY2
-rw-r--r--lib/libpm.c27
2 files changed, 14 insertions, 15 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index bf880087..49c5dd34 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -15,6 +15,8 @@ not yet  BJH  Release 10.62.00
               pamstereogram: fix bug: garbage in -verbose listing.  Broken
               since 10.61
 
+              MinGW build: various fixes.
+
 12.12.30 BJH  Release 10.61.00
 
               pgmhist: Add -machine option.
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;
 }