gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Functions
gwion_print.c File Reference
#include "gwion_util.h"

Go to the source code of this file.

Functions

 ANN2 (1)
 
static int gw_vasprintf (MemPool mp, char **str, const char *fmt, va_list args)
 
 ANN2 (2)
 

Function Documentation

◆ ANN2() [1/2]

ANN2 ( 1 )

Definition at line 3 of file gwion_print.c.

3 {
4 va_list tmpa;
5 va_copy(tmpa, args);
6 const int size = vsnprintf(NULL, 0, fmt, tmpa);
7 va_end(tmpa);
8 return size;
9}
char const char * fmt
Definition gwion_print.h:2

◆ ANN2() [2/2]

ANN2 ( 2 )

Definition at line 29 of file gwion_print.c.

29 {
30 va_list args;
31 va_start(args, fmt);
32 const int ret = gw_vasprintf(mp, str, fmt, args);
33 va_end(args);
34 return ret;
35}
static int gw_vasprintf(MemPool mp, char **str, const char *fmt, va_list args)
Definition gwion_print.c:12
char ** str
Definition gwion_print.h:2

◆ gw_vasprintf()

static int gw_vasprintf ( MemPool mp,
char ** str,
const char * fmt,
va_list args )
static

Definition at line 12 of file gwion_print.c.

12 {
13 char * base = *str;
14 const size_t base_len = base ? strlen(base) : 0;
15 const int size = fmtlen(fmt, args);
16 if (size < 0) return -1;
17 char *ret = mp_malloc2(mp, base_len + size + 1);
18 if (base) strcpy(ret, base);
19 const int final_len = vsprintf(ret + base_len, fmt, args);
20 if (final_len < 0) {
21 mp_free2(mp, base_len + size + 1, ret);
22 return -1;
23 }
24 if (base) mp_free2(mp, strlen(base), base);
25 *str = ret;
26 return final_len;
27}
#define mp_free2(p, sz, a)
Definition mpool.h:28
#define mp_malloc2(p, sz)
Definition mpool.h:30