Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
vasprintf.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for vasprintf.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

int vasprintf (char **string, const char *fmt, va_list arg_list)
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 3 of file vasprintf.c.

Function Documentation

◆ vasprintf()

int vasprintf ( char **  string,
const char *  fmt,
va_list  arg_list 
)

Definition at line 8 of file vasprintf.c.

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
#define va_copy(d, s)
Definition: stdarg.h:11

References malloc(), va_copy, and va_end.

Referenced by asprintf().