add virAsprintf

This commit is contained in:
Guido Günther 2008-12-15 20:09:29 +00:00
parent e4471a7ac7
commit 36c612b21c
4 changed files with 28 additions and 0 deletions

View File

@ -1,3 +1,9 @@
Mon Dec 15 21:05:56 CET 2008 Guido Günther <agx@sigxcpu.org>
Add virAsprintf as safer asprintf helper
* src/util.c, src/util.h (virAsprintf): new function
* src/libvirt_symver.in: export symbol
Mon Dec 15 16:33:25 CET 2008 Daniel Veillard <veillard@redhat.com>
* src/storage_driver.c: fix a segfault, patch by Miloslav TrmaC

View File

@ -595,6 +595,7 @@ LIBVIRT_PRIVATE_@VERSION@ {
virFileReadPid;
virFileLinkPointsTo;
virParseNumber;
virAsprintf;
virRun;
virSkipSpaces;

View File

@ -1153,6 +1153,26 @@ virParseNumber(const char **str)
return (ret);
}
/**
* virAsprintf
*
* like asprintf but makes sure *strp == NULL on failure
*/
int
virAsprintf(char **strp, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
if ((ret = vasprintf(strp, fmt, ap)) == -1)
*strp = NULL;
va_end(ap);
return ret;
}
/* Compare two MAC addresses, ignoring differences in case,
* as well as leading zeros.
*/

View File

@ -112,6 +112,7 @@ int virMacAddrCompare (const char *mac1, const char *mac2);
void virSkipSpaces(const char **str);
int virParseNumber(const char **str);
int virAsprintf(char **strp, const char *fmt, ...);
#define VIR_MAC_BUFLEN 6
#define VIR_MAC_PREFIX_BUFLEN 3