mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Move alloc_sprintf from xml.cc to nbase.
This commit is contained in:
@@ -395,6 +395,9 @@ int Vsnprintf(char *, size_t, const char *, va_list)
|
|||||||
int Snprintf(char *, size_t, const char *, ...)
|
int Snprintf(char *, size_t, const char *, ...)
|
||||||
__attribute__ ((format (printf, 3, 4)));
|
__attribute__ ((format (printf, 3, 4)));
|
||||||
|
|
||||||
|
char *alloc_vsprintf(const char *fmt, va_list va)
|
||||||
|
__attribute__ ((format (printf, 1, 0)));
|
||||||
|
|
||||||
/* Trivial function that returns nonzero if all characters in str of
|
/* Trivial function that returns nonzero if all characters in str of
|
||||||
length strlength are printable (as defined by isprint()) */
|
length strlength are printable (as defined by isprint()) */
|
||||||
int stringisprintable(const char *str, int strlength);
|
int stringisprintable(const char *str, int strlength);
|
||||||
|
|||||||
@@ -165,6 +165,40 @@ int Snprintf(char *s, size_t n, const char *fmt, ...)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vsprintf into a dynamically allocated buffer, similar to asprintf in
|
||||||
|
Glibc. Return the buffer or NULL on error. */
|
||||||
|
char *alloc_vsprintf(const char *fmt, va_list va) {
|
||||||
|
va_list va_tmp;
|
||||||
|
char *s, *p;
|
||||||
|
int size = 32;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
s = NULL;
|
||||||
|
size = 32;
|
||||||
|
for (;;) {
|
||||||
|
p = (char *) safe_realloc(s, size);
|
||||||
|
if (p == NULL)
|
||||||
|
return NULL;
|
||||||
|
s = p;
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
va_tmp = va;
|
||||||
|
#else
|
||||||
|
va_copy(va_tmp, va);
|
||||||
|
#endif
|
||||||
|
n = vsnprintf(s, size, fmt, va_tmp);
|
||||||
|
|
||||||
|
if (n >= size)
|
||||||
|
size = n + 1;
|
||||||
|
else if (n < 0)
|
||||||
|
size = size * 2;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
/* Trivial function that returns nonzero if all characters in str of length strlength are
|
/* Trivial function that returns nonzero if all characters in str of length strlength are
|
||||||
printable (as defined by isprint()) */
|
printable (as defined by isprint()) */
|
||||||
int stringisprintable(const char *str, int strlength) {
|
int stringisprintable(const char *str, int strlength) {
|
||||||
|
|||||||
36
xml.cc
36
xml.cc
@@ -170,42 +170,6 @@ struct xml_writer {
|
|||||||
|
|
||||||
static struct xml_writer xml;
|
static struct xml_writer xml;
|
||||||
|
|
||||||
static char *alloc_vsprintf(const char *fmt, va_list va) __attribute__ ((format (printf, 1, 0)));
|
|
||||||
|
|
||||||
/* vsprintf into a dynamically allocated buffer, similar to asprintf in
|
|
||||||
Glibc. Return the buffer or NULL on error. */
|
|
||||||
static char *alloc_vsprintf(const char *fmt, va_list va) {
|
|
||||||
va_list va_tmp;
|
|
||||||
char *s, *p;
|
|
||||||
int size = 32;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
s = NULL;
|
|
||||||
size = 32;
|
|
||||||
for (;;) {
|
|
||||||
p = (char *) safe_realloc(s, size);
|
|
||||||
if (p == NULL)
|
|
||||||
return NULL;
|
|
||||||
s = p;
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
va_tmp = va;
|
|
||||||
#else
|
|
||||||
va_copy(va_tmp, va);
|
|
||||||
#endif
|
|
||||||
n = vsnprintf(s, size, fmt, va_tmp);
|
|
||||||
|
|
||||||
if (n >= size)
|
|
||||||
size = n + 1;
|
|
||||||
else if (n < 0)
|
|
||||||
size = size * 2;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Escape a string for inclusion in XML. This gets <>&, "' for attribute
|
/* Escape a string for inclusion in XML. This gets <>&, "' for attribute
|
||||||
values, -- for inside comments, and characters with value > 0x7F. It
|
values, -- for inside comments, and characters with value > 0x7F. It
|
||||||
also gets control characters with value < 0x20 to avoid parser
|
also gets control characters with value < 0x20 to avoid parser
|
||||||
|
|||||||
Reference in New Issue
Block a user