~donmcc/astr

ref: da1e8f414d3ebbcc625064018e67e92082c78723 astr/astr.h -rw-r--r-- 1.2 KiB
da1e8f41Don McCaughey Install automake package on Debian Linux build. 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef ASTR_H_INCLUDED
#define ASTR_H_INCLUDED


#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>


char *
astr_alloc_formatted(char const *format, ...);

size_t
astr_formatted_length(char const *format, ...);

size_t
astr_formatted_length_from_va_list(char const *format, va_list arguments);

int
astr_realloc_append_formatted(char **s, char const *format, ...);

int
astr_realloc_append_formatted_from_va_list(char **s, 
                                           char const *format, 
                                           va_list arguments);


inline char *
astr_alloc_empty(void)
{
    return calloc(1, sizeof(char));
}

inline char *
astr_alloc_formatted_from_va_list(char const *format, va_list arguments)
{
    char *s = NULL;
    int result = astr_realloc_append_formatted_from_va_list(&s, format, arguments);
    return (0 == result) ? s : NULL;
}

inline int
astr_cmp(char const *s1, char const *s2)
{
    if (s1 == s2) return 0;
    if (!s1) return -1;
    if (!s2) return 1;
    return strcmp(s1, s2);
}

inline bool
astr_empty(char const *s)
{
    return !s || !s[0];
}

inline bool
astr_eq(char const *s1, char const *s2)
{
    return 0 == astr_cmp(s1, s2);
}


#endif