From 56940cdb32a6338ed5beb1d723ca1b5d4a5944e3 Mon Sep 17 00:00:00 2001 From: Vincent Torri Date: Fri, 4 Feb 2011 09:16:11 +0000 Subject: [PATCH] * src/lib/evil_stdio.c: * src/lib/evil_stdio.h: Add asprintf() function. Add documentation for vasprintf(). Use _vcprintf() instead of vsnprintf() to get the length of the string, as recommended by MSDN. SVN revision: 56705 --- legacy/evil/ChangeLog | 9 +++++++ legacy/evil/src/lib/evil_stdio.c | 22 ++++++++++++---- legacy/evil/src/lib/evil_stdio.h | 45 +++++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog index 67470568e4..c1f9fe0143 100644 --- a/legacy/evil/ChangeLog +++ b/legacy/evil/ChangeLog @@ -1,3 +1,12 @@ +2011-02-04 Vincent Torri + + * src/lib/evil_stdio.c: + * src/lib/evil_stdio.h: + Add asprintf() function. + Add documentation for vasprintf(). + Use _vcprintf() instead of vsnprintf() to get the length + of the string, as recommended by MSDN. + 2011-01-06 Vincent Torri * src/lib/evil_stdio.c: diff --git a/legacy/evil/src/lib/evil_stdio.c b/legacy/evil/src/lib/evil_stdio.c index 1fa4922ed6..cf44367709 100644 --- a/legacy/evil/src/lib/evil_stdio.c +++ b/legacy/evil/src/lib/evil_stdio.c @@ -214,20 +214,32 @@ int evil_fclose_native(FILE *stream) #endif /* _WIN32_WCE */ -#ifdef _WIN32 - int vasprintf(char **strp, const char *fmt, va_list ap) { char *res; int len; - len = _vsnprintf(NULL, 0, fmt, ap) + 1; + len = _vscprintf(fmt, ap) + 1; res = (char *)malloc(len); if (!res) return -1; *strp = res; - return vsprintf(res, fmt, ap); + len = vsprintf(res, fmt, ap); + if (len < 0) len = -1; + + return len; } -#endif /* _WIN32 */ +int +asprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + int res; + + va_start(ap, fmt); + res = vasprintf(strp, fmt, ap); + va_end(ap); + + return res; +} diff --git a/legacy/evil/src/lib/evil_stdio.h b/legacy/evil/src/lib/evil_stdio.h index 7d40c1047c..fa6846fed1 100644 --- a/legacy/evil/src/lib/evil_stdio.h +++ b/legacy/evil/src/lib/evil_stdio.h @@ -54,11 +54,50 @@ EAPI int evil_fclose_native(FILE *stream); #endif /* _WIN32_WCE */ -#ifdef _WIN32 - +/** + * @brief Print allocated string using a va_list. + * + * @param strp The returned pointer of the allocated string. + * @param fmt The format string. + * @param ap The variable argument list. + * @return -1 on failure, the length of the printed string. + * + * This function allocates a buffer large enough to hold the output + * including the terminating null byte, and return a pointer to it + * into @p strp. The format @p fmt is the same than the one used with + * printf(). When not needed anymore, the pointer returned in @p strp + * must be freed. On error (memory allocation failure or other error), + * this function returns -1 and the content of @p strp is undefined, + * otherwise it returns the length of the string (not including the + * terminating null byte). + * + * Conformity: GNU extension. + * + * Supported OS: Windows XP, CE. + */ EAPI int vasprintf(char **strp, const char *fmt, va_list ap); -#endif /* _WIN32 */ +/** + * @brief Print allocated string using a variable number of arguments. + * + * @param strp The returned pointer of the allocated string. + * @param fmt The format string. + * @return -1 on failure, the length of the printed string. + * + * This function allocates a buffer large enough to hold the output + * including the terminating null byte, and return a pointer to it + * into @p strp. The format @p fmt is the same than the one used with + * printf(). When not needed anymore, the pointer returned in @p strp + * must be freed. On error (memory allocation failure or other error), + * this function returns -1 and the content of @p strp is undefined, + * otherwise it returns the length of the string (not including the + * terminating null byte). + * + * Conformity: GNU extension. + * + * Supported OS: Windows XP, CE. + */ +EAPI int asprintf(char **strp, const char *fmt, ...); /**