* 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
This commit is contained in:
Vincent Torri 2011-02-04 09:16:11 +00:00
parent 6dbbb69012
commit 56940cdb32
3 changed files with 68 additions and 8 deletions

View File

@ -1,3 +1,12 @@
2011-02-04 Vincent Torri <doursse at users dot sf dot net>
* 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 <doursse at users dot sf dot net>
* src/lib/evil_stdio.c:

View File

@ -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;
}

View File

@ -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, ...);
/**