File: asprintf.c

package info (click to toggle)
fio 3.41-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,012 kB
  • sloc: ansic: 82,290; python: 9,862; sh: 6,067; makefile: 813; yacc: 204; lex: 184
file content (42 lines) | stat: -rw-r--r-- 662 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include "oslib/asprintf.h"

#ifndef CONFIG_HAVE_VASPRINTF
int vasprintf(char **strp, const char *fmt, va_list ap)
{
	va_list ap_copy;
	char *str;
	int len;

#ifdef va_copy
	va_copy(ap_copy, ap);
#else
	__va_copy(ap_copy, ap);
#endif
	len = vsnprintf(NULL, 0, fmt, ap_copy);
	va_end(ap_copy);

	if (len < 0)
		return len;

	len++;
	str = malloc(len);
	*strp = str;
	return str ? vsnprintf(str, len, fmt, ap) : -1;
}
#endif

#ifndef CONFIG_HAVE_ASPRINTF
int asprintf(char **strp, const char *fmt, ...)
{
	va_list arg;
	int done;

	va_start(arg, fmt);
	done = vasprintf(strp, fmt, arg);
	va_end(arg);

	return done;
}
#endif