diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-11-23 22:33:18 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-11-23 22:33:18 -0800 |
commit | d59fe3c0501ec07b725004de86c1a8adac966092 (patch) | |
tree | 9c1b1a0ad3a0087862c3207f104ed9e132bfd29c | |
parent | 747e066281b78909e5c9703f639c0813b14c385f (diff) |
Add local copy of asprintf()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | save.c | 45 | ||||
-rw-r--r-- | smproxy.h | 5 |
3 files changed, 56 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index ea49c18..26bd5f4 100644 --- a/configure.ac +++ b/configure.ac @@ -31,13 +31,18 @@ AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AM_MAINTAINER_MODE +# Set common system defines for POSIX extensions, such as _GNU_SOURCE +# Must be called before any macros that run the compiler (like +# AC_PROG_LIBTOOL or XORG_DEFAULT_OPTIONS) to avoid autoconf errors. +AC_USE_SYSTEM_EXTENSIONS + # Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS m4_ifndef([XORG_MACROS_VERSION], [m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])]) XORG_MACROS_VERSION(1.8) XORG_DEFAULT_OPTIONS -AC_CHECK_FUNCS([mkstemp mktemp]) +AC_CHECK_FUNCS([asprintf mkstemp mktemp]) # Checks for pkg-config packages PKG_CHECK_MODULES(SMPROXY, [sm ice xt xmuu]) @@ -45,6 +45,51 @@ static char * unique_filename ( char *path, char *prefix ); static char * unique_filename ( char *path, char *prefix, int *pFd ); #endif +#ifndef HAVE_ASPRINTF +# include <stdarg.h> + +/* sprintf variant found in newer libc's which allocates string to print to */ +_X_HIDDEN int _X_ATTRIBUTE_PRINTF(2,3) +asprintf(char ** ret, const char *format, ...) +{ + char buf[256]; + int len; + va_list ap; + + va_start(ap, format); + len = vsnprintf(buf, sizeof(buf), format, ap); + va_end(ap); + + if (len < 0) + return -1; + + if (len < sizeof(buf)) + { + *ret = strdup(buf); + } + else + { + *ret = malloc(len + 1); /* snprintf doesn't count trailing '\0' */ + if (*ret != NULL) + { + va_start(ap, format); + len = vsnprintf(*ret, len + 1, format, ap); + va_end(ap); + if (len < 0) { + free(*ret); + *ret = NULL; + } + } + } + + if (*ret == NULL) + return -1; + + return len; +} +#endif + + static int write_byte (FILE *file, unsigned char b) @@ -107,3 +107,8 @@ extern char * LookupClientID ( WinInfo *theWindow ); extern WinInfo *win_head; #define SAVEFILE_VERSION 1 + +#ifndef HAVE_ASPRINTF +_X_HIDDEN int _X_ATTRIBUTE_PRINTF(2,3) asprintf(char ** ret, + const char *format, ...); +#endif |