12 size_t tokenize(const char *str, const char *delim, char *tokens[], size_t max_tokens ) {
17 strncpy(tmp, str, PATH_MAX);
18 char *p = strtok(tmp, delim);
19 if (max_tokens < 1 || max_tokens > MAX_TOKENS) {
24 tokens[cnt++] = strdup(p);
25 while(cnt < max_tokens && p != NULL) {
26 p = strtok(NULL, delim);
28 tokens[cnt++] = strdup(p);
35 void free_strings(char **array, int n)
39 for(i = 0; i < n; i++) {
40 if (array[i] != NULL) {
47 int read_line(const int fd, char* ptr, const unsigned int maxlen)
54 if((rc = sdb_read(fd, c, 1)) != 1)
55 return -1; // eof or read err
63 return -1; // no space
67 * The standard strncpy() function does not guarantee that the resulting string is null terminated.
68 * char ntbs[NTBS_SIZE];
69 * strncpy(ntbs, source, sizeof(ntbs)-1);
70 * ntbs[sizeof(ntbs)-1] = '\0'
72 char *s_strncpy(char *dest, const char *source, size_t n) {
75 while (n && (*dest++ = *source++)) {