source: libabac/abac_util.c @ 9a411d7

abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change on this file since 9a411d7 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
RevLine 
[7f25a67f]1#include <err.h>
2#include <stdlib.h>
3#include <string.h>
4
5/**
6 * Malloc, fatal on error.
7 */
[3c251d0]8void *abac_xmalloc(size_t size) {
[7f25a67f]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 */
[3c251d0]21char *abac_xstrdup(char *source) {
[7f25a67f]22    char *ret;
23
[ff3d104]24    if (source == NULL)
25        return NULL;
26
[7f25a67f]27    ret = strdup(source);
28    if (ret == NULL)
29        err(1, "strdup");
30
31    return ret;
32}
[9a411d7]33
34/**
35 * Split a string based on the given delimiter.
36 */
37void 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.