mirror of
https://github.com/michaelrsweet/mxml.git
synced 2024-11-08 13:39:58 +00:00
Added snprintf() emulation function for test program (STR #32)
This commit is contained in:
parent
c27692f2d0
commit
9fb36b4a2f
4
CHANGES
4
CHANGES
@ -1,10 +1,12 @@
|
|||||||
CHANGES - 2007-04-17
|
CHANGES - 2007-04-18
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
CHANGES IN Mini-XML 2.3
|
CHANGES IN Mini-XML 2.3
|
||||||
|
|
||||||
- Added two exceptions to the LGPL to support static
|
- Added two exceptions to the LGPL to support static
|
||||||
linking of applications against Mini-XML.
|
linking of applications against Mini-XML.
|
||||||
|
- Added snprintf() emulation function for test program (STR
|
||||||
|
#32)
|
||||||
- Added the _CRT_SECURE_NO_DEPRECATE definition when
|
- Added the _CRT_SECURE_NO_DEPRECATE definition when
|
||||||
building on VC++ 2005 (STR #36)
|
building on VC++ 2005 (STR #36)
|
||||||
- mxmlLoad*() did not detect missing > characters in
|
- mxmlLoad*() did not detect missing > characters in
|
||||||
|
10
config.h.in
10
config.h.in
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Configuration file for Mini-XML, a small XML-like file parsing library.
|
* Configuration file for Mini-XML, a small XML-like file parsing library.
|
||||||
*
|
*
|
||||||
* Copyright 2003-2005 by Michael Sweet.
|
* Copyright 2003-2007 by Michael Sweet.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
@ -35,9 +35,10 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do we have the vsnprintf() function?
|
* Do we have the snprintf() and vsnprintf() functions?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef HAVE_SNPRINTF
|
||||||
#undef HAVE_VSNPRINTF
|
#undef HAVE_VSNPRINTF
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +61,11 @@ extern char *_mxml_strdup(const char *);
|
|||||||
extern char *_mxml_strdupf(const char *, ...);
|
extern char *_mxml_strdupf(const char *, ...);
|
||||||
extern char *_mxml_vstrdupf(const char *, va_list);
|
extern char *_mxml_vstrdupf(const char *, va_list);
|
||||||
|
|
||||||
|
# ifndef HAVE_SNPRINTF
|
||||||
|
extern int _mxml_snprintf(char *, size_t, const char *, ...);
|
||||||
|
# define snprintf _mxml_snprintf
|
||||||
|
# endif /* !HAVE_SNPRINTF */
|
||||||
|
|
||||||
# ifndef HAVE_VSNPRINTF
|
# ifndef HAVE_VSNPRINTF
|
||||||
extern int _mxml_vsnprintf(char *, size_t, const char *, va_list);
|
extern int _mxml_vsnprintf(char *, size_t, const char *, va_list);
|
||||||
# define vsnprintf _mxml_vsnprintf
|
# define vsnprintf _mxml_vsnprintf
|
||||||
|
3
configure
vendored
3
configure
vendored
@ -3199,7 +3199,8 @@ fi
|
|||||||
|
|
||||||
if test "x$use_vsnprintf" != xyes; then
|
if test "x$use_vsnprintf" != xyes; then
|
||||||
|
|
||||||
for ac_func in vsnprintf
|
|
||||||
|
for ac_func in snprintf vsnprintf
|
||||||
do
|
do
|
||||||
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
echo "$as_me:$LINENO: checking for $ac_func" >&5
|
echo "$as_me:$LINENO: checking for $ac_func" >&5
|
||||||
|
@ -104,7 +104,7 @@ if test "x$use_ansi" != xyes; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x$use_vsnprintf" != xyes; then
|
if test "x$use_vsnprintf" != xyes; then
|
||||||
AC_CHECK_FUNCS(vsnprintf)
|
AC_CHECK_FUNCS(snprintf vsnprintf)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dnl Shared library support...
|
dnl Shared library support...
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
<li>Added two exceptions to the LGPL to support static
|
<li>Added two exceptions to the LGPL to support static
|
||||||
linking of applications against Mini-XML.</li>
|
linking of applications against Mini-XML.</li>
|
||||||
|
|
||||||
|
<li>Added snprintf() emulation function for test program
|
||||||
|
(STR #32)</li>
|
||||||
|
|
||||||
<li>Added the _CRT_SECURE_NO_DEPRECATE definition when
|
<li>Added the _CRT_SECURE_NO_DEPRECATE definition when
|
||||||
building on VC++ 2005 (STR #36)</li>
|
building on VC++ 2005 (STR #36)</li>
|
||||||
|
|
||||||
|
119
mxml-string.c
119
mxml-string.c
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* String functions for Mini-XML, a small XML-like file parsing library.
|
* String functions for Mini-XML, a small XML-like file parsing library.
|
||||||
*
|
*
|
||||||
* Copyright 2003-2005 by Michael Sweet.
|
* Copyright 2003-2007 by Michael Sweet.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
@ -17,10 +17,11 @@
|
|||||||
*
|
*
|
||||||
* Contents:
|
* Contents:
|
||||||
*
|
*
|
||||||
|
* _mxml_snprintf() - Format a string.
|
||||||
* _mxml_strdup() - Duplicate a string.
|
* _mxml_strdup() - Duplicate a string.
|
||||||
* _mxml_strdupf() - Format and duplicate a string.
|
* _mxml_strdupf() - Format and duplicate a string.
|
||||||
* _mxml_vstrdupf() - Format and duplicate a string.
|
|
||||||
* _mxml_vsnprintf() - Format a string into a fixed size buffer.
|
* _mxml_vsnprintf() - Format a string into a fixed size buffer.
|
||||||
|
* _mxml_vstrdupf() - Format and duplicate a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -30,6 +31,30 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_SNPRINTF
|
||||||
|
/*
|
||||||
|
* '_mxml_snprintf()' - Format a string.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int /* O - Number of bytes formatted */
|
||||||
|
_mxml_snprintf(char *buffer, /* I - Output buffer */
|
||||||
|
size_t bufsize, /* I - Size of output buffer */
|
||||||
|
const char *format, /* I - Printf-style format string */
|
||||||
|
...) /* I - Additional arguments as needed */
|
||||||
|
{
|
||||||
|
va_list ap; /* Argument list */
|
||||||
|
int bytes; /* Number of bytes formatted */
|
||||||
|
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
bytes = vsnprintf(buffer, bufsize, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return (bytes);
|
||||||
|
}
|
||||||
|
#endif /* HAVE_SNPRINTF */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* '_mxml_strdup()' - Duplicate a string.
|
* '_mxml_strdup()' - Duplicate a string.
|
||||||
*/
|
*/
|
||||||
@ -77,51 +102,6 @@ _mxml_strdupf(const char *format, /* I - Printf-style format string */
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* '_mxml_vstrdupf()' - Format and duplicate a string.
|
|
||||||
*/
|
|
||||||
|
|
||||||
char * /* O - New string pointer */
|
|
||||||
_mxml_vstrdupf(const char *format, /* I - Printf-style format string */
|
|
||||||
va_list ap) /* I - Pointer to additional arguments */
|
|
||||||
{
|
|
||||||
int bytes; /* Number of bytes required */
|
|
||||||
char *buffer, /* String buffer */
|
|
||||||
temp[256]; /* Small buffer for first vsnprintf */
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* First format with a tiny buffer; this will tell us how many bytes are
|
|
||||||
* needed...
|
|
||||||
*/
|
|
||||||
|
|
||||||
bytes = vsnprintf(temp, sizeof(temp), format, ap);
|
|
||||||
|
|
||||||
if (bytes < sizeof(temp))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Hey, the formatted string fits in the tiny buffer, so just dup that...
|
|
||||||
*/
|
|
||||||
|
|
||||||
return (strdup(temp));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate memory for the whole thing and reformat to the new, larger
|
|
||||||
* buffer...
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ((buffer = calloc(1, bytes + 1)) != NULL)
|
|
||||||
vsnprintf(buffer, bytes + 1, format, ap);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the new string...
|
|
||||||
*/
|
|
||||||
|
|
||||||
return (buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_VSNPRINTF
|
#ifndef HAVE_VSNPRINTF
|
||||||
/*
|
/*
|
||||||
* '_mxml_vsnprintf()' - Format a string into a fixed size buffer.
|
* '_mxml_vsnprintf()' - Format a string into a fixed size buffer.
|
||||||
@ -427,6 +407,51 @@ _mxml_vsnprintf(char *buffer, /* O - Output buffer */
|
|||||||
#endif /* !HAVE_VSNPRINTF */
|
#endif /* !HAVE_VSNPRINTF */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* '_mxml_vstrdupf()' - Format and duplicate a string.
|
||||||
|
*/
|
||||||
|
|
||||||
|
char * /* O - New string pointer */
|
||||||
|
_mxml_vstrdupf(const char *format, /* I - Printf-style format string */
|
||||||
|
va_list ap) /* I - Pointer to additional arguments */
|
||||||
|
{
|
||||||
|
int bytes; /* Number of bytes required */
|
||||||
|
char *buffer, /* String buffer */
|
||||||
|
temp[256]; /* Small buffer for first vsnprintf */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First format with a tiny buffer; this will tell us how many bytes are
|
||||||
|
* needed...
|
||||||
|
*/
|
||||||
|
|
||||||
|
bytes = vsnprintf(temp, sizeof(temp), format, ap);
|
||||||
|
|
||||||
|
if (bytes < sizeof(temp))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Hey, the formatted string fits in the tiny buffer, so just dup that...
|
||||||
|
*/
|
||||||
|
|
||||||
|
return (strdup(temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate memory for the whole thing and reformat to the new, larger
|
||||||
|
* buffer...
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ((buffer = calloc(1, bytes + 1)) != NULL)
|
||||||
|
vsnprintf(buffer, bytes + 1, format, ap);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the new string...
|
||||||
|
*/
|
||||||
|
|
||||||
|
return (buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* End of "$Id$".
|
* End of "$Id$".
|
||||||
*/
|
*/
|
||||||
|
@ -46,9 +46,10 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do we have the vsnprintf() function?
|
* Do we have the snprintf() and vsnprintf() functions?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*#undef HAVE_SNPRINTF */
|
||||||
/*#undef HAVE_VSNPRINTF */
|
/*#undef HAVE_VSNPRINTF */
|
||||||
|
|
||||||
|
|
||||||
@ -70,6 +71,11 @@ extern char *mxml_strdup(const char *);
|
|||||||
|
|
||||||
extern char *mxml_strdupf(const char *, va_list);
|
extern char *mxml_strdupf(const char *, va_list);
|
||||||
|
|
||||||
|
# ifndef HAVE_SNPRINTF
|
||||||
|
extern int _mxml_snprintf(char *, size_t, const char *, ...);
|
||||||
|
# define snprintf _mxml_snprintf
|
||||||
|
# endif /* !HAVE_SNPRINTF */
|
||||||
|
|
||||||
# ifndef HAVE_VSNPRINTF
|
# ifndef HAVE_VSNPRINTF
|
||||||
extern int mxml_vsnprintf(char *, size_t, const char *, va_list);
|
extern int mxml_vsnprintf(char *, size_t, const char *, va_list);
|
||||||
# define vsnprintf mxml_vsnprintf
|
# define vsnprintf mxml_vsnprintf
|
||||||
|
Loading…
Reference in New Issue
Block a user