diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2015-01-18 11:21:45 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2015-01-25 19:51:44 -0800 |
commit | ca04f74887d53c75e794f643f7e860ba588c3a57 (patch) | |
tree | b43c370c08e83ed32b0199c35a111fe3ae4ba175 | |
parent | fba83e45a8d5dc2ca920ec6c49446d2b54c2db5c (diff) |
makestrs: Use asprintf() if available
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | util/makestrs.c | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 34e6aab..3633ec6 100644 --- a/configure.ac +++ b/configure.ac @@ -64,7 +64,10 @@ if test x"$CC_FOR_BUILD" = x; then fi fi AC_SUBST([CC_FOR_BUILD]) -CPPFLAGS_FOR_BUILD=${CPPFLAGS_FOR_BUILD-${CPPFLAGS}} +DEFAULT_CPPFLAGS_FOR_BUILD="${CPPFLAGS}" +AC_CHECK_FUNC(asprintf, + [DEFAULT_CPPFLAGS_FOR_BUILD="${DEFAULT_CPPFLAGS_FOR_BUILD} -DHAVE_ASPRINTF"]) +CPPFLAGS_FOR_BUILD=${CPPFLAGS_FOR_BUILD-${DEFAULT_CPPFLAGS_FOR_BUILD}} AC_SUBST(CPPFLAGS_FOR_BUILD) DEFAULT_CFLAGS_FOR_BUILD="${CFLAGS} ${CWARNFLAGS}" CFLAGS_FOR_BUILD=${CFLAGS_FOR_BUILD-${DEFAULT_CFLAGS_FOR_BUILD}} diff --git a/util/makestrs.c b/util/makestrs.c index f872ec8..5764849 100644 --- a/util/makestrs.c +++ b/util/makestrs.c @@ -90,19 +90,26 @@ static int solaris_abi_names = FALSE; static char* includedir = NULL; static FILE *ifopen(const char *file, const char *mode) { +#ifndef HAVE_ASPRINTF size_t len; +#endif char *buffer; FILE *ret; if (includedir == NULL) return fopen(file, mode); +#ifdef HAVE_ASPRINTF + if (asprintf(&buffer, "%s/%s", includedir, file) == -1) + return NULL; +#else len = strlen(file) + strlen(includedir) + 1; buffer = (char*)malloc(len + 1); if (buffer == NULL) return NULL; snprintf(buffer, len + 1, "%s/%s", includedir, file); +#endif ret = fopen(buffer, mode); @@ -269,13 +276,23 @@ static void WriteHeader (char *tagline, File *phile, int abi) /* do the right thing for Motif, i.e. avoid _XmXmStrDefs_h_ */ if (strcmp (prefixstr, "Xm") == 0) { +#ifdef HAVE_ASPRINTF + if (asprintf (&fileprotstr, "_%s_", phile->name) == -1) + exit (1); +#else if ((fileprotstr = malloc (strlen (phile->name) + 3)) == NULL) exit (1); (void) sprintf (fileprotstr, "_%s_", phile->name); +#endif } else { +#ifdef HAVE_ASPRINTF + if (asprintf (&fileprotstr, "_%s%s_", prefixstr, phile->name) == -1) + exit (1); +#else if ((fileprotstr = malloc (strlen (phile->name) + strlen (prefixstr) + 3)) == NULL) exit (1); (void) sprintf (fileprotstr, "_%s%s_", prefixstr, phile->name); +#endif } for (tmp = fileprotstr; *tmp; tmp++) if (*tmp == '.') *tmp = '_'; |