From ebcdc687d02e34240bd98b9f1396225eee4e4240 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 23 Jan 2024 18:15:13 -0800 Subject: Use asprintf() if available Signed-off-by: Alan Coopersmith --- configure.ac | 3 +++ get_rload.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/configure.ac b/configure.ac index 43fdf0b..347249b 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,9 @@ m4_ifndef([XORG_MACROS_VERSION], XORG_MACROS_VERSION(1.8) XORG_DEFAULT_OPTIONS +# Checks for library functions. +AC_CHECK_FUNCS([asprintf]) + # Internationalization & localization support AC_SEARCH_LIBS([gettext], [intl], [USE_GETTEXT="yes"], [USE_GETTEXT="no"]) AC_MSG_CHECKING([where to install localized messages]) diff --git a/get_rload.c b/get_rload.c index c3f9dfb..c17598f 100644 --- a/get_rload.c +++ b/get_rload.c @@ -1,3 +1,6 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include #include @@ -44,6 +47,12 @@ void GetRLoadPoint( *(double *)call_data = 0.0; /* to be on the safe side */ if (fname == NULL) { +#ifdef HAVE_ASPRINTF + if (asprintf(&fname, "%s/whod.%s", _PATH_RWHODIR, resources.remote) < 0) { + perror("GetRLoadPoint: asprintf() failed"); + exit(1); + } +#else if ((fname = malloc(strlen(_PATH_RWHODIR)+strlen("/whod.")+strlen(resources.remote)+1)) == NULL) { fprintf(stderr,"GetRLoadPoint: malloc() failed\n"); exit(1); @@ -51,6 +60,7 @@ void GetRLoadPoint( strcpy(fname,_PATH_RWHODIR); strcat(fname,"/whod."); strcat(fname,resources.remote); +#endif } if ((f = open(fname, O_RDONLY, 0)) < 0) return; -- cgit v1.2.3