diff options
author | Alexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de> | 2004-12-03 11:57:42 +0000 |
---|---|---|
committer | Alexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de> | 2004-12-03 11:57:42 +0000 |
commit | 16a683f4d164899ecfdafb853f48cff10fd13fd4 (patch) | |
tree | 3d1a06522092c82b4b872308d07a61e38532ef63 /os/xprintf.c | |
parent | fe2a2213d1db8700f6078379f86ebe8827793c20 (diff) |
Bugzilla #1865, https://bugs.freedesktop.org/show_bug.cgi?id=1865 Added
X(NF)printf and X(NF)vprintf functions which allocate the buffer with
X(NF)alloc
Bugzilla #1865, https://bugs.freedesktop.org/show_bug.cgi?id=1865 extend
snprintf to work on NULL.
Diffstat (limited to 'os/xprintf.c')
-rw-r--r-- | os/xprintf.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/os/xprintf.c b/os/xprintf.c new file mode 100644 index 000000000..49279c102 --- /dev/null +++ b/os/xprintf.c @@ -0,0 +1,64 @@ +#include "Xos.h" +#include "os.h" +#include <stdarg.h> +#include <stdio.h> + +char * +Xvprintf(const char *format, va_list va) +{ + char *ret; + int size; + va_list va2; + + va_copy(va2, va); + size = vsnprintf(NULL, 0, format, va2); + va_end(va2); + + ret = (char *)Xalloc(size + 1); + if (ret == NULL) + return NULL; + + vsnprintf(ret, size + 1, format, va); + ret[size] = 0; + return ret; +} + +char *Xprintf(const char *format, ...) +{ + char *ret; + va_list va; + va_start(va, format); + ret = Xvprintf(format, va); + va_end(va); + return ret; +} + +char * +XNFvprintf(const char *format, va_list va) +{ + char *ret; + int size; + va_list va2; + + va_copy(va2, va); + size = vsnprintf(NULL, 0, format, va2); + va_end(va2); + + ret = (char *)XNFalloc(size + 1); + if (ret == NULL) + return NULL; + + vsnprintf(ret, size + 1, format, va); + ret[size] = 0; + return ret; +} + +char *XNFprintf(const char *format, ...) +{ + char *ret; + va_list va; + va_start(va, format); + ret = XNFvprintf(format, va); + va_end(va); + return ret; +} |