-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.h
42 lines (35 loc) · 1.07 KB
/
util.h
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
#ifndef C_TOML_UTIL_H
#define C_TOML_UTIL_H
#include <stdio.h>
#include <stdbool.h>
#include <c-string/lib.h>
#include "lib.h"
#define __inline__ static inline __attribute__((always_inline)) \
__attribute__((unused))
#undef bool
typedef _Bool bool;
/* __inline__
StringBuffer read_file(char *path, int *size_p)
{
FILE *fp = fopen(path, "r");
if (fp == NULL)
return NULL;
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
StringBuffer text = StringBuffer_with_length(size + 1);
fread(text, size, 1, fp);
text[size] = '\0';
fclose(fp);
*size_p = size;
return text;
} */
#define in_range(c, x, y) (((c) >= (x)) && ((c) <= (y)))
#define is_letter(c) \
(in_range(c, 'A', 'Z') || in_range(c, 'a', 'z'))
#define is_digit(c) in_range(c, '0', '9')
#define is_hex(c) \
(is_digit(c) || in_range(c, 'A', 'F') || in_range(c, 'a', 'f'))
#define is_empty(c) \
((c) == ' ' || (c) == '\t' || (c) == '\n')
#endif /* C_TOML_UTIL_H */