aboutsummaryrefslogtreecommitdiffstats
path: root/include/dbs/util.h
blob: bda2c32da733a70071a38c33e14fceb45f58f19c (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
#ifndef __UTIL_H
#define __UTIL_H

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

#define writeputs(str) write(STDOUT_FILENO, str, strlen(str));

#ifdef cJSON__h

static inline int js_getInt(cJSON *js, char *name)
{
    cJSON *number = cJSON_GetObjectItemCaseSensitive(js, name);
    if(cJSON_IsNumber(number))
        return number->valueint;

    return -1;
}

static inline char *js_getStr(cJSON *js, char *name)
{
    cJSON *str = cJSON_GetObjectItemCaseSensitive(js, name);
    if(cJSON_IsString(str))
        return str->valuestring;
    return NULL;
}

#endif

#endif