]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Drop win32-specific asprintf implementation (#1246)
authorMichal Suchánek <msuchanek@suse.de>
Fri, 19 Jan 2024 13:02:05 +0000 (14:02 +0100)
committerGitHub <noreply@github.com>
Fri, 19 Jan 2024 13:02:05 +0000 (14:02 +0100)
asprintf is implemented by rrd_snprintf anyway, the win32-specific
implementation is redundant.

Same with the non-vasprintf conditional in rrd_info.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
12 files changed:
CHANGES
Makefile.am
src/rrd_info.c
src/rrd_list.c
src/rrd_snprintf.h
win32/Makefile.msc
win32/Makefile_vcpkg.msc
win32/asprintf.c [deleted file]
win32/asprintf.h [deleted file]
win32/librrd-8.vcxproj
win32/rrd_config.h
win32/vasprintf-msvc.c [deleted file]

diff --git a/CHANGES b/CHANGES
index d73881b1f65bc8afad87c5436f54745460d3398c..c46ba62652e6a787927728229e6051bc625744fa 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -45,6 +45,10 @@ Features
 * Constify argv argument to library functions
   Without this users of library function that want to pass in const strings need to duplicate them to avoid compiler warnings
 
+* Avoid multiple implementations of asprintf
+  The locale-independent rrd_asprintf is equivalent to platform-provided snprintf when strings and integers are formatted.
+  There is no user of vasprintf-msvc that is locale-dependent, therefore this implementation can be replaced with rrd_vasprintf.
+
 RRDtool 1.8.0 - 2022-03-13
 ==========================
 
index a7d270c40c7d1f452543284a119e7f2caa77ff31..816320b93786bd7d0aed62cad2711d039ccbf92f 100644 (file)
@@ -26,7 +26,7 @@ EXTRA_DIST = COPYRIGHT CHANGES TODO CONTRIBUTORS THREADS VERSION LICENSE \
              win32/rrdcgi.rc win32/rrd_config.h \
              win32/rrd.sln win32/rrdtool.rc win32/rrdtool.vcxproj win32/rrdupdate.rc \
              win32/rrdcgi.vcxproj win32/rrdupdate.vcxproj win32/uac.manifest \
-             win32/asprintf.c win32/asprintf.h win32/dirent.h win32/vasprintf-msvc.c
+             win32/dirent.h
 
 CLEANFILES = config.cache
 
index eb0d4e4dec7dd7fb3345913e3dc6436bde1bf2c4..9ed01528ea1a87dc61ce33a0b112f2d65b6790cc 100644 (file)
@@ -8,9 +8,7 @@
 #include "rrd_rpncalc.h"
 #include "rrd_client.h"
 #include <stdarg.h>
-#ifdef _MSC_VER
-#include "asprintf.h"   /* for vasprintf() here */
-#endif
+#include "rrd_snprintf.h"   /* for vasprintf() here */
 
 /* allocate memory for string */
 char     *sprintf_alloc(
@@ -19,25 +17,12 @@ char     *sprintf_alloc(
 {
     char     *str = NULL;
     va_list   argp;
-#ifdef HAVE_VASPRINTF
     va_start( argp, fmt );
     if (vasprintf( &str, fmt, argp ) == -1){
         va_end(argp);
         rrd_set_error ("vasprintf failed.");
         return(NULL);
     }
-#else
-    int       maxlen = 1024 + strlen(fmt);
-    str = (char*)malloc(sizeof(char) * (maxlen + 1));
-    if (str != NULL) {
-        va_start(argp, fmt);
-#ifdef HAVE_VSNPRINTF
-        vsnprintf(str, maxlen, fmt, argp);
-#else
-        vsprintf(str, fmt, argp);
-#endif
-    }
-#endif /* HAVE_VASPRINTF */
     va_end(argp);
     return str;
 }
index 5ac36d8dbdac93167a2cfeb2a6ffc2c67487eda5..eb2e5a9cc4380b0a03357de0223e50013456ef5d 100644 (file)
@@ -5,7 +5,6 @@
 #ifdef _MSC_VER
 #include "win32-glob.h"    /* from https://sourceforge.net/projects/sox/ */
 #include "dirent.h"        /* from https://github.com/tronkko/dirent */
-#include "asprintf.h"      /* from http://asprintf.insanecoding.org */
 #else
 #if defined(__MINGW32__) && !defined(HAVE_GLOB_H)   /* MinGW has glob.h, MinGW-w64 not (yet?) */
 #include "win32/win32-glob.h"    /* from https://sourceforge.net/projects/sox/ */
index 484f0d6ed6e32e56c22f703ecdcc0fcf5210539d..5e8d0a85b144ea36ba9d0b36262e213da6a805c7 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef RRD_SNPRINTF_H
 #define RRD_SNPRINTF_H
 
+#include "rrd_config.h"
+
 #ifdef  __cplusplus
 extern    "C" {
 #endif
@@ -12,8 +14,14 @@ int rrd_vsnprintf(char *, size_t, const char *, va_list);
 int rrd_snprintf(char *, size_t, const char *, ...);
 
 int rrd_vasprintf(char **, const char *, va_list);
+#ifndef HAVE_VASPRINTF
+#define vasprintf rrd_vasprintf
+#endif
 
 int rrd_asprintf(char **, const char *, ...);
+#ifndef HAVE_ASPRINTF
+#define asprintf rrd_asprintf
+#endif
 
 #ifdef  __cplusplus
 }
index 2a998f30633c672b47f1d2a38dc9de7cd9ef0606..c46f8165d36c95e896ebcfd34cd160a932658aa1 100644 (file)
@@ -81,8 +81,6 @@ RRD_LIB_OBJ_LIST = \
         $(TOP)/src/rrd_utils.obj \\r
         $(TOP)/src/rrd_version.obj \\r
         $(TOP)/src/rrd_xport.obj \\r
-        $(TOP)/win32/asprintf.obj \\r
-        $(TOP)/win32/vasprintf-msvc.obj \\r
         $(TOP)/win32/win32-glob.obj\r
 # win32comp.obj is not added to RRD_LIB_OBJ_LIST, because definitions are already in rrd_thread_safe_nt.obj\r
 \r
index b3fa78d286b21b86f49be9df3e9f853fd7b564ae..50ae9dd7e1b402426d8833707096bf25058991f2 100644 (file)
@@ -82,8 +82,6 @@ RRD_LIB_OBJ_LIST = \
         $(TOP)/src/rrd_utils.obj \\r
         $(TOP)/src/rrd_version.obj \\r
         $(TOP)/src/rrd_xport.obj \\r
-        $(TOP)/win32/asprintf.obj \\r
-        $(TOP)/win32/vasprintf-msvc.obj \\r
         $(TOP)/win32/win32-glob.obj\r
 # win32comp.obj is not added to RRD_LIB_OBJ_LIST, because definitions are already in rrd_thread_safe_nt.obj\r
 \r
diff --git a/win32/asprintf.c b/win32/asprintf.c
deleted file mode 100644 (file)
index bb6fe93..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/)
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
-
-#include "asprintf.h"
-
-int asprintf(char **strp, const char *fmt, ...)
-{
-  int r;
-  va_list ap;
-  va_start(ap, fmt);
-  r = vasprintf(strp, fmt, ap);
-  va_end(ap);
-  return(r);
-}
diff --git a/win32/asprintf.h b/win32/asprintf.h
deleted file mode 100644 (file)
index 577a638..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/)
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
-
-#ifndef INSANE_ASPRINTF_H
-#define INSANE_ASPRINTF_H
-
-#ifndef __cplusplus
-#include <stdarg.h>
-#else
-#include <cstdarg>
-extern "C"
-{
-#endif
-
-#define insane_free(ptr) { free(ptr); ptr = 0; }
-
-int vasprintf(char **strp, const char *fmt, va_list ap);
-int asprintf(char **strp, const char *fmt, ...);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
index e3a600b605bcbb4732ea1cddf7926c731c44b3cd..2dac3268fc9c47047b0578fb63576cd5c76343bb 100644 (file)
     <ClCompile Include="..\src\rrd_utils.c" />
     <ClCompile Include="..\src\rrd_version.c" />
     <ClCompile Include="..\src\rrd_xport.c" />
-    <ClCompile Include="asprintf.c" />
-    <ClCompile Include="vasprintf-msvc.c" />
     <ClCompile Include="win32-glob.c" />
   </ItemGroup>
   <ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index 7cc345a7a9204bc0d2b474dca606a2727be55f4f..a0406550a3b1e1eea7169be92ca85680d8fc2556 100644 (file)
@@ -52,9 +52,6 @@
 #  endif
 #endif
 
-/* Define to 1 if you have the `asprintf' function. */
-#define HAVE_ASPRINTF 1
-
 /* Define to 1 if you have the `chdir' function. */
 #define HAVE_CHDIR 1
 
 /* Define to 1 if you have the `uintptr_t' standard type. */
 #define HAVE_UINTPTR_T 1
 
-/* Define to 1 if you have the `vasprintf' function. */
-#define HAVE_VASPRINTF 1
-
 /* Define to 1 if you have the `va_copy' function or macro. */
 #define HAVE_VA_COPY 1
 
diff --git a/win32/vasprintf-msvc.c b/win32/vasprintf-msvc.c
deleted file mode 100644 (file)
index 2d951f8..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/)
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include "asprintf.h"
-
-int vasprintf(char **strp, const char *fmt, va_list ap)
-{
-  int r = -1, size = _vscprintf(fmt, ap);
-
-  if ((size >= 0) && (size < INT_MAX))
-  {
-    *strp = (char *)malloc(size+1); //+1 for null
-    if (*strp)
-    {
-      r = vsnprintf(*strp, size+1, fmt, ap);  //+1 for null
-      if ((r < 0) || (r > size))
-      {
-        insane_free(*strp);
-        r = -1;
-      }
-    }
-  }
-  else { *strp = 0; }
-
-  return(r);
-}
\ No newline at end of file