meiyap1
Last change
on this file since 6e73091 was
9a411d7,
checked in by Mike Ryan <mikeryan@…>, 14 years ago
|
fold intersection into ordinary role object
|
-
Property mode set to
100644
|
File size:
885 bytes
|
Line | |
---|
1 | #include <err.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | |
---|
5 | /** |
---|
6 | * Malloc, fatal on error. |
---|
7 | */ |
---|
8 | void *abac_xmalloc(size_t size) { |
---|
9 | void *ret; |
---|
10 | |
---|
11 | ret = malloc(size); |
---|
12 | if (ret == NULL) |
---|
13 | err(1, "malloc"); |
---|
14 | |
---|
15 | return ret; |
---|
16 | } |
---|
17 | |
---|
18 | /** |
---|
19 | * strdup fatal on error |
---|
20 | */ |
---|
21 | char *abac_xstrdup(char *source) { |
---|
22 | char *ret; |
---|
23 | |
---|
24 | if (source == NULL) |
---|
25 | return NULL; |
---|
26 | |
---|
27 | ret = strdup(source); |
---|
28 | if (ret == NULL) |
---|
29 | err(1, "strdup"); |
---|
30 | |
---|
31 | return ret; |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | * Split a string based on the given delimiter. |
---|
36 | */ |
---|
37 | void abac_split(char *string, char *delim, char **ret, int *num) { |
---|
38 | int len = strlen(delim); |
---|
39 | char *start = string; |
---|
40 | int count = 0; |
---|
41 | |
---|
42 | // split the string by the delim |
---|
43 | while ((start = strstr(string, delim)) != NULL) { |
---|
44 | *start = 0; |
---|
45 | ret[count++] = string; |
---|
46 | string = start + len; |
---|
47 | } |
---|
48 | ret[count++] = string; |
---|
49 | |
---|
50 | *num = count; |
---|
51 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.