libxputty 0.1
Loading...
Searching...
No Matches
Functions
xasprintf.h File Reference

Multiplatform implementation of asprintf() from: https://stackoverflow.com/questions/40159892/using-asprintf-on-windows define _GNU_SOURCE to use the GNU asprintf extension instead this one. More...

Go to the source code of this file.

Functions

int _vscprintf_so (const char *format, va_list pargs)
 
int vasprintf (char **strp, const char *fmt, va_list ap)
 
int asprintf (char *strp[], const char *fmt,...)
 

Detailed Description

Multiplatform implementation of asprintf() from: https://stackoverflow.com/questions/40159892/using-asprintf-on-windows define _GNU_SOURCE to use the GNU asprintf extension instead this one.

Definition in file xasprintf.h.

Function Documentation

◆ _vscprintf_so()

int _vscprintf_so ( const char *  format,
va_list  pargs 
)

Definition at line 16 of file xasprintf.c.

16 {
17 int retval;
18 va_list argcopy;
19 va_copy(argcopy, pargs);
20 retval = vsnprintf(NULL, 0, format, argcopy);
21 va_end(argcopy);
22 return retval;
23}

Referenced by vasprintf().

◆ asprintf()

int asprintf ( char *  strp[],
const char *  fmt,
  ... 
)

Definition at line 36 of file xasprintf.c.

36 {
37 va_list ap;
38 va_start(ap, fmt);
39 int r = vasprintf(strp, fmt, ap);
40 va_end(ap);
41 return r;
42}
int vasprintf(char **strp, const char *fmt, va_list ap)
Definition xasprintf.c:25

References vasprintf().

Referenced by add_root_directory(), combobox_add_entry(), combobox_rename_entry(), fp_get_files(), fp_init(), hyperlink_pressed(), locale_from_utf8(), os_get_home_dir(), and utf8_from_locale().

◆ vasprintf()

int vasprintf ( char **  strp,
const char *  fmt,
va_list  ap 
)

Definition at line 25 of file xasprintf.c.

25 {
26 int len = _vscprintf_so(fmt, ap);
27 if (len == -1) return -1;
28 char *str = malloc((size_t) len + 1);
29 if (!str) return -1;
30 int r = vsnprintf(str, len + 1, fmt, ap);
31 if (r == -1) return free(str), -1;
32 *strp = str;
33 return r;
34}
int _vscprintf_so(const char *format, va_list pargs)
Definition xasprintf.c:16

References _vscprintf_so().

Referenced by asprintf().