Check for vasprintf() and add a replacement if it wasn't found.
This commit is contained in:
parent
4bba48a6a0
commit
81fa8da4ce
26
configure
vendored
26
configure
vendored
@ -4,6 +4,7 @@
|
||||
# Ensure that we do not inherit these from env
|
||||
STRLCPY=
|
||||
STRLCAT=
|
||||
VASPRINTF=
|
||||
OS=
|
||||
BUILD=
|
||||
HOST=
|
||||
@ -275,6 +276,29 @@ if [ -n "$BUILD_PIE" ]; then
|
||||
check_compiler_flag pie "" PROG_LDFLAGS
|
||||
fi
|
||||
|
||||
#
|
||||
# Check for vasprintf().
|
||||
#
|
||||
printf "Checking for vasprintf() ... "
|
||||
cat <<EOF >_vasprintf.c
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
vasprintf(NULL, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
if $XCC _vasprintf.c -o _vasprintf 2>/dev/null; then
|
||||
VASPRINTF=yes
|
||||
else
|
||||
VASPRINTF=no
|
||||
fi
|
||||
echo "$VASPRINTF."
|
||||
rm -f _vasprint.c _vasprintf
|
||||
if [ "$VASPRINTF" = "yes" ]; then
|
||||
echo "CPPFLAGS += -DHAVE_VASPRINTF" >> $CONFIG_MK
|
||||
fi
|
||||
|
||||
#
|
||||
# Check for strlcpy().
|
||||
#
|
||||
@ -298,6 +322,7 @@ rm -f _strlcpy.c _strlcpy
|
||||
if [ "$STRLCPY" = no ]; then
|
||||
echo "COMPAT_SRCS += compat/strlcpy.o" >>$CONFIG_MK
|
||||
echo "#include \"strlcpy.h\"" >>$CONFIG_H
|
||||
else
|
||||
echo "CPPFLAGS += -DHAVE_STRLCPY" >> $CONFIG_MK
|
||||
fi
|
||||
|
||||
@ -323,6 +348,7 @@ rm -f _strlcat.c _strlcat
|
||||
if [ "$STRLCAT" = no ]; then
|
||||
echo "COMPAT_SRCS += compat/strlcat.o" >>$CONFIG_MK
|
||||
echo "#include \"strlcat.h\"" >>$CONFIG_H
|
||||
else
|
||||
echo "CPPFLAGS += -DHAVE_STRLCAT" >>$CONFIG_MK
|
||||
fi
|
||||
|
||||
|
35
lib/util.c
35
lib/util.c
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2010 Juan Romero Pardines.
|
||||
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -45,7 +45,6 @@
|
||||
* @brief Utility routines
|
||||
* @defgroup util Utility functions
|
||||
*/
|
||||
|
||||
static const char *rootdir;
|
||||
static const char *cachedir;
|
||||
static int flags;
|
||||
@ -493,6 +492,7 @@ xbps_get_flags(void)
|
||||
return flags;
|
||||
}
|
||||
|
||||
#ifdef HAVE_VASPRINTF
|
||||
char *
|
||||
xbps_xasprintf(const char *fmt, ...)
|
||||
{
|
||||
@ -500,9 +500,38 @@ xbps_xasprintf(const char *fmt, ...)
|
||||
char *buf;
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (vasprintf(&buf, fmt, ap) == -1)
|
||||
if (vasprintf(&buf, fmt, ap) == -1) {
|
||||
va_end(ap);
|
||||
return NULL;
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
return buf;
|
||||
}
|
||||
#else
|
||||
char *
|
||||
xbps_xasprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap, aq;
|
||||
size_t len;
|
||||
int res;
|
||||
char *buf;
|
||||
|
||||
va_start(aq, fmt);
|
||||
va_copy(ap, aq);
|
||||
len = vsnprintf(NULL, 0, fmt, aq) + 1;
|
||||
if ((buf = malloc(len)) == NULL) {
|
||||
va_end(ap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
res = vsnprintf(buf, len, fmt, ap);
|
||||
if (res < 0 || res >= (int)len) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
#endif /* !HAVE_VASPRINTF */
|
||||
|
Loading…
Reference in New Issue
Block a user