about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-27 22:58:39 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-27 22:58:39 +0000
commit0cc7ccdefa6f1fd3f8e23254c34f956156136a39 (patch)
tree8b56862abcdbd7778974c8e96eeefe9fbb2bb09e /lib
parent6748da2ec290df7a6430dcdc222b5d7e00808d4e (diff)
downloadnetpbm-mirror-0cc7ccdefa6f1fd3f8e23254c34f956156136a39.tar.gz
netpbm-mirror-0cc7ccdefa6f1fd3f8e23254c34f956156136a39.tar.xz
netpbm-mirror-0cc7ccdefa6f1fd3f8e23254c34f956156136a39.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4619 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/util/nstring.c64
-rw-r--r--lib/util/nstring.h16
-rw-r--r--lib/util/vasprintf.c13
3 files changed, 12 insertions, 81 deletions
diff --git a/lib/util/nstring.c b/lib/util/nstring.c
index 6663ebf0..623fd7b7 100644
--- a/lib/util/nstring.c
+++ b/lib/util/nstring.c
@@ -1,26 +1,6 @@
 /*=============================================================================
                                nstring.c
 ===============================================================================
-
-  pm_snprintf (and pm_vsnprintf) in this file used to be derived from
-  'portable_snprintf' from
-  http://www.ijs.si/software/snprintf/snprintf-2.2.tar.gz, because not all
-  system C libraries had snprintf.  But in 2013, we extended that snprintf to
-  implement %f by calling 'snprintf' in the system C library, just to see if
-  it caused any build failures.  As of August 2022, there had been no
-  complaints of problems caused by this reliance on the system providing
-  snprintf, so we just made pm_snprintf a wrapper of snprintf for everything.
-
-  Eventually we will remove pm_snprintf and pm_vsnprintf altogether and their
-  callers will call 'snprintf' and 'vsnprintf' instead
-
-  Note that snprintf is required by the C99 standard.
-
-  The code from which pm_snprintf was formerly derived was protected by
-  copyright and licensed to the public under GPL.  A user in August 2022 noted
-  that GPL was insufficient for his use of it, making him unable to use
-  libnetpbm.
-
   Code in this file is contributed to the public domain by its authors.
 =============================================================================*/
 #define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */
@@ -59,46 +39,6 @@ pm_strnlen(const char * const s,
 
 
 
-void
-pm_vsnprintf(char *       const str,
-             size_t       const maxSize,
-             const char * const fmt,
-             va_list            ap,
-             size_t *     const sizeP) {
-
-    int rc;
-
-    rc = vsnprintf(str, maxSize, fmt, ap);
-
-    assert((size_t)rc == rc);
-
-    *sizeP = (size_t)rc;
-}
-
-
-
-int
-pm_snprintf(char *       const dest,
-            size_t       const maxSize,
-            const char * const fmt,
-            ...) {
-
-    size_t size;
-    va_list ap;
-
-    va_start(ap, fmt);
-
-    pm_vsnprintf(dest, maxSize, fmt, ap, &size);
-
-    va_end(ap);
-
-    assert(size <= INT_MAX);
-
-    return size;
-}
-
-
-
 /* When a function that is supposed to return a malloc'ed string cannot
    get the memory for it, it should return 'pm_strsol'.  That has a much
    better effect on the caller, if the caller doesn't explicitly allow for
@@ -144,7 +84,7 @@ pm_asprintf(const char ** const resultP,
 
     va_start(varargs, fmt);
 
-    pm_vsnprintf(NULL, 0, fmt, varargs, &dryRunLen);
+    vsnprintf(NULL, 0, fmt, varargs, &dryRunLen);
 
     va_end(varargs);
 
@@ -161,7 +101,7 @@ pm_asprintf(const char ** const resultP,
 
             va_start(varargs, fmt);
 
-            pm_vsnprintf(buffer, allocSize, fmt, varargs, &realLen);
+            vsnprintf(buffer, allocSize, fmt, varargs, &realLen);
 
             assert(realLen == dryRunLen);
             va_end(varargs);
diff --git a/lib/util/nstring.h b/lib/util/nstring.h
index 1f03e4f2..7ade39ef 100644
--- a/lib/util/nstring.h
+++ b/lib/util/nstring.h
@@ -128,8 +128,7 @@ strncaseeq(const char * const comparand,
    subroutines whose names are similar.  They're here because not all standard
    C libraries have them.
 
-   The GNU C library has all of them.  All but the oldest standard C libraries
-   have snprintf().
+   The GNU C library has all of them.
 
    There are slight differences between the asprintf() family and that
    found in other libraries:
@@ -155,19 +154,6 @@ size_t
 pm_strnlen(const char * const s,
            size_t       const maxlen);
 
-int
-pm_snprintf(char *       const dest,
-            size_t       const maxSize,
-            const char * const fmt,
-            ...) PM_GNU_PRINTF_ATTR(3,4);
-
-void
-pm_vsnprintf(char *       const str,
-             size_t       const maxSize,
-             const char * const fmt,
-             va_list            ap,
-             size_t *     const sizeP);
-
 const char *
 pm_strdup(const char * const arg);
 
diff --git a/lib/util/vasprintf.c b/lib/util/vasprintf.c
index a947f763..fbca457a 100644
--- a/lib/util/vasprintf.c
+++ b/lib/util/vasprintf.c
@@ -1,9 +1,11 @@
+#define _C99_SOURCE  /* Make sure snprintf() is in stdio.h */
 #define _GNU_SOURCE
    /* Because of conditional compilation, this is GNU source only if the C
       library is GNU.
    */
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 #include "pm_config.h"
 #include "pm_c_util.h"
@@ -36,7 +38,7 @@ pm_vasprintf(const char ** const resultP,
        simply make two copies of the va_list variable in normal C
        fashion, but on others you need va_copy, which is a relatively
        recent invention.  In particular, the simple va_list copy
-       failed on an AMD64 Gcc Linux system in March 2006.  
+       failed on an AMD64 Gcc Linux system in March 2006.
 
        So instead, we just allocate 4K and truncate or waste as
        necessary.
@@ -49,14 +51,14 @@ pm_vasprintf(const char ** const resultP,
     */
     size_t const allocSize = 4096;
     result = malloc(allocSize);
-    
+
     if (result == NULL)
         *resultP = pm_strsol;
     else {
         size_t realLen;
 
-        pm_vsnprintf(result, allocSize, format, varargs, &realLen);
-        
+        realLen = vsnprintf(result, allocSize, format, varargs);
+
         if (realLen >= allocSize)
             strcpy(result + allocSize - 15, "<<<TRUNCATED");
 
@@ -75,3 +77,6 @@ pm_vasprintf_knows_float(void) {
     return false;
 #endif
 }
+
+
+