Debian Codegraph @

usr/lib/common/aix/asprintf.h

raw symbols SCIP
1 /*
2 * COPYRIGHT (c) International Business Machines Corp. 2024
3 *
4 * This program is provided under the terms of the Common Public License,
5 * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
6 * software constitutes recipient's acceptance of CPL-1.0 terms which can be
7 * found in the file LICENSE file or at
8 * https://opensource.org/licenses/cpl1.0.php
9 */
10 #ifndef UTIL_LINUX_ASPRINTF_H
11 #define UTIL_LINUX_ASPRINTF_H
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <stdarg.h>
16
17 #ifndef HAVE_VASPRINTF
18 static inline
19 int vasprintf(char **strp, const char *fmt, va_list ap)
20 {
21 int str_size = -1, len;
22 va_list cap;
23
24 va_copy(cap, ap);
25
26 len = vsnprintf(0, 0, fmt, cap);
27 va_end(cap);
28
29 if (len < 0)
30 return -1;
31
32 *strp = (char *)malloc (len + 1);
33
34 if (!*strp)
35 return -1;
36
37 str_size = vsnprintf(*strp, len + 1, fmt, ap);
38 if (str_size < 0 || str_size >= len + 1) {
39 free(*strp);
40 str_size = -1;
41 }
42 return str_size;
43 }
44 #endif
45
46 #ifndef HAVE_ASPRINTF
47 static inline
48 int asprintf(char **strp, const char *fmt, ...)
49 {
50 int res;
51 va_list ap;
52
53 va_start (ap, fmt);
54 res = vasprintf (strp, fmt, ap);
55 va_end (ap);
56
57 return res;
58 }
59 #endif
60
61 #endif