aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
blob: a6c0aff64df89e95e78e1edb5fe05395b96a581a (plain)
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
#ifndef MAGI_INCLUDED_UTILS
#define MAGI_INCLUDED_UTILS


static void lowercase(char *str)
{
    if (str) {
        while (*str) {
            *str = tolower(*str);
            ++str;
        }
    }
}

static char *create_str(const char *begin, const char *end)
{
    char *res;
    res = malloc(end - begin + 1);
    if (res) {
        memcpy(res, begin, end - begin);
        res[end - begin] = 0;
    }
    return res;
}

static char *str_alloc(int len)
{
    char *str = malloc(len + 1);
    if (str) {
        str[len] = 0;
    } else {
        magi_log("[request] Cannot allocate string.");
    }
    return str;
}


#endif