#include #include #include /** * Malloc, fatal on error. */ void *abac_xmalloc(size_t size) { void *ret; ret = malloc(size); if (ret == NULL) err(1, "malloc"); return ret; } /** * strdup fatal on error */ char *abac_xstrdup(char *source) { char *ret; if (source == NULL) return NULL; ret = strdup(source); if (ret == NULL) err(1, "strdup"); return ret; } /** * Split a string based on the given delimiter. */ void abac_split(char *string, char *delim, char **ret, int *num) { int len = strlen(delim); char *start = string; int count = 0; // split the string by the delim while ((start = strstr(string, delim)) != NULL) { *start = 0; ret[count++] = string; string = start + len; } ret[count++] = string; *num = count; }