From de325d72c4d5211784dc38e089be02c213a6f47c Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Sun, 7 Jan 2024 12:11:02 +0100 Subject: [PATCH] Drop win32-specific asprintf implementation asprintf is implemented by rrd_snprintf anyway, the win32-specific implementation is redundant. Signed-off-by: Michal Suchanek --- Makefile.am | 2 +- src/rrd_info.c | 4 +--- src/rrd_list.c | 2 +- win32/Makefile.msc | 2 -- win32/Makefile_vcpkg.msc | 2 -- win32/asprintf.c | 27 -------------------------- win32/asprintf.h | 37 ----------------------------------- win32/librrd-8.vcxproj | 4 +--- win32/rrd_config.h | 6 ------ win32/vasprintf-msvc.c | 42 ---------------------------------------- 10 files changed, 4 insertions(+), 124 deletions(-) delete mode 100644 win32/asprintf.c delete mode 100644 win32/asprintf.h delete mode 100644 win32/vasprintf-msvc.c diff --git a/Makefile.am b/Makefile.am index a7d270c40..816320b93 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/rrd_info.c b/src/rrd_info.c index eb0d4e4de..62e9f20a0 100644 --- a/src/rrd_info.c +++ b/src/rrd_info.c @@ -8,9 +8,7 @@ #include "rrd_rpncalc.h" #include "rrd_client.h" #include -#ifdef _MSC_VER -#include "asprintf.h" /* for vasprintf() here */ -#endif +#include "rrd_snprintf.h" /* for vasprintf() here */ /* allocate memory for string */ char *sprintf_alloc( diff --git a/src/rrd_list.c b/src/rrd_list.c index 6e96220ea..cf4a4ca16 100644 --- a/src/rrd_list.c +++ b/src/rrd_list.c @@ -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/ */ @@ -18,6 +17,7 @@ #include "rrd_tool.h" #include "rrd_client.h" +#include "rrd_snprintf.h" static char *move_past_prefix(const char *prefix, const char *string) { diff --git a/win32/Makefile.msc b/win32/Makefile.msc index 2a998f306..c46f8165d 100644 --- a/win32/Makefile.msc +++ b/win32/Makefile.msc @@ -81,8 +81,6 @@ RRD_LIB_OBJ_LIST = \ $(TOP)/src/rrd_utils.obj \ $(TOP)/src/rrd_version.obj \ $(TOP)/src/rrd_xport.obj \ - $(TOP)/win32/asprintf.obj \ - $(TOP)/win32/vasprintf-msvc.obj \ $(TOP)/win32/win32-glob.obj # win32comp.obj is not added to RRD_LIB_OBJ_LIST, because definitions are already in rrd_thread_safe_nt.obj diff --git a/win32/Makefile_vcpkg.msc b/win32/Makefile_vcpkg.msc index b3fa78d28..50ae9dd7e 100644 --- a/win32/Makefile_vcpkg.msc +++ b/win32/Makefile_vcpkg.msc @@ -82,8 +82,6 @@ RRD_LIB_OBJ_LIST = \ $(TOP)/src/rrd_utils.obj \ $(TOP)/src/rrd_version.obj \ $(TOP)/src/rrd_xport.obj \ - $(TOP)/win32/asprintf.obj \ - $(TOP)/win32/vasprintf-msvc.obj \ $(TOP)/win32/win32-glob.obj # win32comp.obj is not added to RRD_LIB_OBJ_LIST, because definitions are already in rrd_thread_safe_nt.obj diff --git a/win32/asprintf.c b/win32/asprintf.c deleted file mode 100644 index bb6fe9338..000000000 --- a/win32/asprintf.c +++ /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 index 577a63862..000000000 --- a/win32/asprintf.h +++ /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 -#else -#include -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 diff --git a/win32/librrd-8.vcxproj b/win32/librrd-8.vcxproj index e3a600b60..2dac3268f 100644 --- a/win32/librrd-8.vcxproj +++ b/win32/librrd-8.vcxproj @@ -427,8 +427,6 @@ - - @@ -468,4 +466,4 @@ - \ No newline at end of file + diff --git a/win32/rrd_config.h b/win32/rrd_config.h index 7cc345a7a..a0406550a 100644 --- a/win32/rrd_config.h +++ b/win32/rrd_config.h @@ -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 @@ -103,9 +100,6 @@ /* 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 index 2d951f850..000000000 --- a/win32/vasprintf-msvc.c +++ /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 -#include -#include -#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