~donmcc/astr

ref: f4dd4ca4751396f256f3b9dd6c65c265c1a33ef1 astr/astr.c -rw-r--r-- 636 bytes
f4dd4ca4Don McCaughey Change "formatted" to "format". 1 year, 10 months ago
                                                                                
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
#include "astr.h"

#include <errno.h>
#include <stdio.h>


extern char *
astr_alloc_empty(void);


char *
astr_alloc_format(char const *format, ...)
{
    va_list arguments;
    va_start(arguments, format);
    char *s = astr_alloc_format_args(format, arguments);
    va_end(arguments);
    return s;
}


char *
astr_alloc_format_args(char const *format, va_list arguments)
{
    if (!format) {
        errno = EINVAL;
        return NULL;
    }

    char *s;
    int chars_printed = vasprintf(&s, format, arguments);
    if (chars_printed < 0) return NULL;
    return s;
}


extern bool
astr_eq_bytes(char const *s1, char const *s2);