mei_rt2mei_rt2_fix_1
Last change
on this file since 9335cfa was
7727f26,
checked in by Mei <mei@…>, 13 years ago
|
1) add environment variables DUMP_DB, ABAC_CN.
ABAC_CN will switch to using CNs for keyid insead of SHAs
2) add/modified couple of doc files.
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[7f25a67f] | 1 | #include <err.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <string.h> |
---|
[7727f26] | 4 | #include <stdio.h> |
---|
| 5 | |
---|
| 6 | static int debug=0; |
---|
[7f25a67f] | 7 | |
---|
| 8 | /** |
---|
| 9 | * Malloc, fatal on error. |
---|
| 10 | */ |
---|
[3c251d0] | 11 | void *abac_xmalloc(size_t size) { |
---|
[7f25a67f] | 12 | void *ret; |
---|
| 13 | |
---|
| 14 | ret = malloc(size); |
---|
| 15 | if (ret == NULL) |
---|
| 16 | err(1, "malloc"); |
---|
| 17 | |
---|
| 18 | return ret; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * strdup fatal on error |
---|
| 23 | */ |
---|
[3c251d0] | 24 | char *abac_xstrdup(char *source) { |
---|
[7f25a67f] | 25 | char *ret; |
---|
| 26 | |
---|
[7727f26] | 27 | if (source == NULL) { |
---|
| 28 | if(debug) printf("BAD -> duping null string..\n"); |
---|
[ff3d104] | 29 | return NULL; |
---|
[7727f26] | 30 | } |
---|
[ff3d104] | 31 | |
---|
[7f25a67f] | 32 | ret = strdup(source); |
---|
| 33 | if (ret == NULL) |
---|
| 34 | err(1, "strdup"); |
---|
| 35 | |
---|
| 36 | return ret; |
---|
| 37 | } |
---|
[9a411d7] | 38 | |
---|
[c586a3c] | 39 | /* make a brand new string with or without being trimmed */ |
---|
| 40 | char *abac_trim_quotes(char *string) { |
---|
| 41 | char *tmp=abac_xstrdup(string); |
---|
| 42 | int len=strlen(tmp); |
---|
| 43 | if( (tmp[len-1] == '\'' || tmp[len-1] == '"') && |
---|
| 44 | (tmp[0] == '\'' || tmp[0] == '"')) { |
---|
| 45 | tmp[len-1]='\0'; |
---|
| 46 | char *ntmp=abac_xstrdup(&tmp[1]); |
---|
| 47 | free(tmp); |
---|
| 48 | return ntmp; |
---|
| 49 | } |
---|
| 50 | return tmp; |
---|
| 51 | } |
---|
| 52 | |
---|
[9a411d7] | 53 | /** |
---|
| 54 | * Split a string based on the given delimiter. |
---|
| 55 | */ |
---|
| 56 | void abac_split(char *string, char *delim, char **ret, int *num) { |
---|
| 57 | int len = strlen(delim); |
---|
| 58 | char *start = string; |
---|
| 59 | int count = 0; |
---|
| 60 | |
---|
| 61 | // split the string by the delim |
---|
| 62 | while ((start = strstr(string, delim)) != NULL) { |
---|
| 63 | *start = 0; |
---|
| 64 | ret[count++] = string; |
---|
| 65 | string = start + len; |
---|
| 66 | } |
---|
| 67 | ret[count++] = string; |
---|
| 68 | |
---|
| 69 | *num = count; |
---|
| 70 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.