Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
vasprintf.c
Go to the documentation of this file.
1 // From musl libc
2 
3 #define _GNU_SOURCE
4 #include <stdarg.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 
8 int vasprintf(char** string, const char* fmt, va_list arg_list)
9 {
10  va_list arg_list_copy;
11  va_copy(arg_list_copy, arg_list);
12  int l = vsnprintf(0, 0, fmt, arg_list_copy);
13  va_end(arg_list_copy);
14 
15  if(l < 0 || !(*string = malloc((size_t)l + 1U)))
16  {
17  return -1;
18  }
19 
20  return vsnprintf(*string, (size_t)l + 1U, fmt, arg_list);
21 }
Definition: gdtoaimp.h:284
#define va_end(v)
Definition: stdarg.h:9
void * malloc(size_t size)
Allocates size bytes of uninitialized storage.
__builtin_va_list va_list
Definition: stdarg.h:13
int vasprintf(char **string, const char *fmt, va_list arg_list)
Definition: vasprintf.c:8
#define va_copy(d, s)
Definition: stdarg.h:11