diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-10-24 19:08:41 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-10-25 10:55:56 -0700 |
commit | 3f1a7aac4b4c91e0d7b3c355b4148245ab8eb24d (patch) | |
tree | eb0d4f74fb92bd8b3137cc7d7da42068e63320df | |
parent | ca05c39d1c52734661d703d92c39cc3669c7b520 (diff) |
Use asprintf() instead of malloc/strcpy/strcat, if its available
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | showrgb.c | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 534e41d..bf7974a 100644 --- a/configure.ac +++ b/configure.ac @@ -27,6 +27,7 @@ AC_INIT([rgb], [1.0.5], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [rgb]) AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS([config.h]) +AC_USE_SYSTEM_EXTENSIONS # Initialize Automake AM_INIT_AUTOMAKE([foreign dist-bzip2]) @@ -37,6 +38,8 @@ m4_ifndef([XORG_MACROS_VERSION], XORG_MACROS_VERSION(1.8) XORG_DEFAULT_OPTIONS +AC_CHECK_FUNCS([asprintf]) + PKG_CHECK_MODULES(RGB, xproto) AC_MSG_CHECKING([for rgb database location]) @@ -124,9 +124,16 @@ dumprgb (const char *filename) int lineno = 0; int red, green, blue; +#ifdef HAVE_ASPRINTF + if (asprintf(&path, "%s.txt", filename) == -1) { + perror (ProgramName); + exit (1); + } +#else path = (char *)malloc(strlen(filename) + 5); strcpy(path, filename); strcat(path, ".txt"); +#endif if (!(rgb = fopen(path, "r"))) { fprintf (stderr, "%s: unable to open rgb database \"%s\"\n", |