source: libabac/abac_util.c @ 9806e76

mei_rt2mei_rt2_fix_1meiyap-rt1rt2
Last change on this file since 9806e76 was c586a3c, checked in by Mei <mei@…>, 12 years ago

1) add support for float static range constraint
2) add a testcase for testing float static range constraint
3) add runall-fast (skipping the creddy part)

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <err.h>
2#include <stdlib.h>
3#include <string.h>
4
5/**
6 * Malloc, fatal on error.
7 */
8void *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 */
21char *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/* make a brand new string with or without being trimmed */
35char *abac_trim_quotes(char *string) {
36    char *tmp=abac_xstrdup(string);
37    int len=strlen(tmp);
38    if( (tmp[len-1] == '\'' || tmp[len-1] == '"') &&
39                       (tmp[0] == '\'' || tmp[0] == '"')) {
40       tmp[len-1]='\0';
41       char *ntmp=abac_xstrdup(&tmp[1]);
42       free(tmp);
43       return ntmp;
44    }
45    return tmp;
46}
47
48/**
49 * Split a string based on the given delimiter.
50 */
51void abac_split(char *string, char *delim, char **ret, int *num) {
52    int len = strlen(delim);
53    char *start = string;
54    int count = 0;
55
56    // split the string by the delim
57    while ((start = strstr(string, delim)) != NULL) {
58        *start = 0;
59        ret[count++] = string;
60        string = start + len;
61    }
62    ret[count++] = string;
63
64    *num = count;
65}
Note: See TracBrowser for help on using the repository browser.