Skip to content

Commit

Permalink
Drop win32-specific asprintf implementation (#1246)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
hramrach committed Jan 19, 2024
1 parent e66ec71 commit b39df92
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 137 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
==========================

Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 1 addition & 16 deletions src/rrd_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/rrd_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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/ */
Expand Down
8 changes: 8 additions & 0 deletions src/rrd_snprintf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef RRD_SNPRINTF_H
#define RRD_SNPRINTF_H

#include "rrd_config.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions win32/Makefile.msc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions win32/Makefile_vcpkg.msc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 0 additions & 27 deletions win32/asprintf.c

This file was deleted.

37 changes: 0 additions & 37 deletions win32/asprintf.h

This file was deleted.

4 changes: 1 addition & 3 deletions win32/librrd-8.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,6 @@
<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>
Expand Down Expand Up @@ -468,4 +466,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
6 changes: 0 additions & 6 deletions win32/rrd_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
42 changes: 0 additions & 42 deletions win32/vasprintf-msvc.c

This file was deleted.

0 comments on commit b39df92

Please sign in to comment.