summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2024-01-23 18:15:13 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-01-23 18:15:13 -0800
commitebcdc687d02e34240bd98b9f1396225eee4e4240 (patch)
tree9fd914cf30e47cb2e0e1e9b8c20837078e7108d4
parentef450fb99630a406c4638d8ba251eac45e434411 (diff)
Use asprintf() if available
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac3
-rw-r--r--get_rload.c10
2 files changed, 13 insertions, 0 deletions
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 <stdio.h>
#include <X11/Intrinsic.h>
@@ -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;