Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -461,23 +461,20 @@ AC_CHECK_FUNC(asprintf, [ case "$host" in *-psp-*) dnl asprintf is broken on the PSP, but snprintf works. have_asprintf="no" - AC_SUBST(ASPRINTF_M, "asprintf.m") ac_cv_snprintf_useful_ret="yes" ;; *) have_asprintf="yes" - AC_DEFINE(OF_HAVE_ASPRINTF, 1, + AC_DEFINE(HAVE_ASPRINTF, 1, [Whether we have asprintf()]) - AC_SUBST(ASPRINTF_DEF, "-DOF_HAVE_ASPRINTF") ;; esac ], [ have_asprintf="no" - AC_SUBST(ASPRINTF_M, "asprintf.m") AC_MSG_CHECKING(whether snprintf returns something useful) AC_CACHE_VAL(ac_cv_snprintf_useful_ret, [ AC_TRY_RUN([ #include Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -6,11 +6,10 @@ OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} OBJFW_BRIDGE_SHARED_LIB = @OBJFW_BRIDGE_SHARED_LIB@ OBJFW_BRIDGE_STATIC_LIB = @OBJFW_BRIDGE_STATIC_LIB@ -ASPRINTF_M = @ASPRINTF_M@ ATOMIC_H = @ATOMIC_H@ AUTORELEASE_M = @AUTORELEASE_M@ BIN_PREFIX = @BIN_PREFIX@ BRIDGE = @BRIDGE@ EXCEPTIONS_A = @EXCEPTIONS_A@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -106,11 +106,10 @@ OFLocking.h \ OFMessagePackRepresentation.h \ OFSerialization.h \ OFTLSSocket.h \ ObjFW.h \ - asprintf.h \ autorelease.h \ ${ATOMIC_H} \ block.h \ instance.h \ macros.h \ @@ -124,11 +123,10 @@ OFMutableDictionary_hashtable.m \ OFMutableSet_hashtable.m \ OFMutableString_UTF8.m \ OFSet_hashtable.m \ OFString_UTF8.m \ - ${ASPRINTF_M} \ ${AUTORELEASE_M} \ codepage_437.m \ ${FOUNDATION_COMPAT_M} \ ${INSTANCE_M} \ iso_8859_15.m \ Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -176,12 +176,11 @@ # import "OFMutex.h" # import "OFRecursiveMutex.h" # import "OFCondition.h" #endif -#import "asprintf.h" #import "base64.h" #import "of_asprintf.h" #import "of_strptime.h" #ifdef OF_HAVE_SOCKETS # import "resolver.h" #endif DELETED src/asprintf.h Index: src/asprintf.h ================================================================== --- src/asprintf.h +++ src/asprintf.h @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "objfw-defs.h" - -#ifndef __STDC_LIMIT_MACROS -# define __STDC_LIMIT_MACROS -#endif -#ifndef __STDC_CONSTANT_MACROS -# define __STDC_CONSTANT_MACROS -#endif - -#ifndef OF_HAVE_ASPRINTF -# include - -# ifdef __cplusplus -extern "C" { -# endif -extern int asprintf(char**, const char*, ...); -extern int vasprintf(char**, const char*, va_list); -# ifdef __cplusplus -} -# endif -#endif DELETED src/asprintf.m Index: src/asprintf.m ================================================================== --- src/asprintf.m +++ src/asprintf.m @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include -#include -#include - -int -vasprintf(char **string, const char *format, va_list arguments) -{ - int length; - va_list argumentsCopy; - - va_copy(argumentsCopy, arguments); - - if ((length = vsnprintf(NULL, 0, format, argumentsCopy)) < 0) - return length; - if ((*string = malloc((size_t)length + 1)) == NULL) - return -1; - - return vsnprintf(*string, (size_t)length + 1, format, arguments); -} - -int -asprintf(char **string, const char *format, ...) -{ - int ret; - va_list arguments; - - va_start(arguments, format); - ret = vasprintf(string, format, arguments); - va_end(arguments); - - return ret; -} Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -1,9 +1,8 @@ #undef OF_APPLE_RUNTIME #undef OF_BIG_ENDIAN #undef OF_FLOAT_BIG_ENDIAN -#undef OF_HAVE_ASPRINTF #undef OF_HAVE_ATOMIC_OPS #undef OF_HAVE_BUILTIN_BSWAP16 #undef OF_HAVE_BUILTIN_BSWAP32 #undef OF_HAVE_BUILTIN_BSWAP64 #undef OF_HAVE_CHMOD Index: src/of_asprintf.m ================================================================== --- src/of_asprintf.m +++ src/of_asprintf.m @@ -25,12 +25,10 @@ #include #import "OFString.h" -#import "asprintf.h" - #define MAX_SUBFORMAT_LEN 64 struct context { const char *format; size_t formatLen; @@ -57,10 +55,41 @@ LENGTH_MODIFIER_Z, LENGTH_MODIFIER_T, LENGTH_MODIFIER_CAPITAL_L } lengthModifier; }; + +#ifndef HAVE_ASPRINTF +static int +vasprintf(char **string, const char *format, va_list arguments) +{ + int length; + va_list argumentsCopy; + + va_copy(argumentsCopy, arguments); + + if ((length = vsnprintf(NULL, 0, format, argumentsCopy)) < 0) + return length; + if ((*string = malloc((size_t)length + 1)) == NULL) + return -1; + + return vsnprintf(*string, (size_t)length + 1, format, arguments); +} + +static int +asprintf(char **string, const char *format, ...) +{ + int ret; + va_list arguments; + + va_start(arguments, format); + ret = vasprintf(string, format, arguments); + va_end(arguments); + + return ret; +} +#endif static bool appendString(struct context *ctx, const char *append, size_t appendLen) { char *newBuf;