-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.h
More file actions
49 lines (39 loc) · 1.43 KB
/
util.h
File metadata and controls
49 lines (39 loc) · 1.43 KB
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
#include <stdint.h>
#define PIPE_OR_RETURN(fd) \
if (pipe(fd) == -1) { \
perror("pipe failed"); \
return 1; \
}
#define FORK_OR_RETURN(pid) \
if ((pid = fork()) == -1) { \
perror("fork failed"); \
return 1; \
}
#define STARTS_WITH(haystack, prefix) \
(strncmp(haystack, prefix, sizeof(prefix) - 1) == 0)
#ifdef __cplusplus
extern "C" {
#endif
// Simple function that removes ANSI color codes by removing everything between
// '\x1b' and 'm' (inclusive, of course). `len` should be the length of the
// string including the NUL byte. Returns the new length of the string (also
// including the NUL byte).
int uncolor(char *b, int len);
enum arg_type {
// Treat the arg like a regular pathspec.
NO_OP,
SINGLE,
RANGE
};
union arg {
int single;
int range[2];
};
typedef struct parsed_arg {
enum arg_type type;
union arg val;
} parsed_arg;
void parse_arg(char *arg, parsed_arg *);
#ifdef __cplusplus
}
#endif