xprintf.c revision fa225cbc
1fa225cbcSrjs/*
2fa225cbcSrjs * Copyright (c) 2004 Alexander Gottwald
3fa225cbcSrjs *
4fa225cbcSrjs * Permission is hereby granted, free of charge, to any person obtaining a
5fa225cbcSrjs * copy of this software and associated documentation files (the "Software"),
6fa225cbcSrjs * to deal in the Software without restriction, including without limitation
7fa225cbcSrjs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8fa225cbcSrjs * and/or sell copies of the Software, and to permit persons to whom the
9fa225cbcSrjs * Software is furnished to do so, subject to the following conditions:
10fa225cbcSrjs *
11fa225cbcSrjs * The above copyright notice and this permission notice shall be included in
12fa225cbcSrjs * all copies or substantial portions of the Software.
13fa225cbcSrjs *
14fa225cbcSrjs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15fa225cbcSrjs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16fa225cbcSrjs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17fa225cbcSrjs * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18fa225cbcSrjs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19fa225cbcSrjs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20fa225cbcSrjs * DEALINGS IN THE SOFTWARE.
21fa225cbcSrjs *
22fa225cbcSrjs * Except as contained in this notice, the name(s) of the above copyright
23fa225cbcSrjs * holders shall not be used in advertising or otherwise to promote the sale,
24fa225cbcSrjs * use or other dealings in this Software without prior written authorization.
25fa225cbcSrjs */
26fa225cbcSrjs
27fa225cbcSrjs#include <string.h>
28fa225cbcSrjs#include <stdarg.h>
29fa225cbcSrjs#include "reg_dumper.h"
30fa225cbcSrjs
31fa225cbcSrjsstatic char *
32fa225cbcSrjsXNFvprintf(const char *format, va_list va)
33fa225cbcSrjs{
34fa225cbcSrjs    char *ret;
35fa225cbcSrjs    int size;
36fa225cbcSrjs    va_list va2;
37fa225cbcSrjs
38fa225cbcSrjs    va_copy(va2, va);
39fa225cbcSrjs    size = vsnprintf(NULL, 0, format, va2);
40fa225cbcSrjs    va_end(va2);
41fa225cbcSrjs
42fa225cbcSrjs    ret = (char *)malloc(size + 1);
43fa225cbcSrjs    if (ret == NULL)
44fa225cbcSrjs        return NULL;
45fa225cbcSrjs
46fa225cbcSrjs    vsnprintf(ret, size + 1, format, va);
47fa225cbcSrjs    ret[size] = 0;
48fa225cbcSrjs    return ret;
49fa225cbcSrjs}
50fa225cbcSrjs
51fa225cbcSrjschar *
52fa225cbcSrjsXNFprintf(const char *format, ...)
53fa225cbcSrjs{
54fa225cbcSrjs    char *ret;
55fa225cbcSrjs    va_list va;
56fa225cbcSrjs    va_start(va, format);
57fa225cbcSrjs    ret = XNFvprintf(format, va);
58fa225cbcSrjs    va_end(va);
59fa225cbcSrjs    return ret;
60fa225cbcSrjs}
61