12 size_t tokenize(const char *str, const char *delim, char *tokens[], size_t max_tokens ) {
18 strncpy(tmp, str, PATH_MAX);
21 char *p = strtok_r(tmp, delim, &ptr);
22 if (max_tokens < 1 || max_tokens > MAX_TOKENS) {
27 tokens[cnt++] = strdup(p);
28 while(cnt < max_tokens && p != NULL) {
29 p = strtok_r(NULL, delim, &ptr);
31 tokens[cnt++] = strdup(p);
38 void free_strings(char **array, int n)
42 for(i = 0; i < n; i++) {
43 if (array[i] != NULL) {
50 int read_line(const int fd, char* ptr, const unsigned int maxlen)
57 if((rc = sdb_read(fd, c, 1)) != 1)
58 return -1; // eof or read err
66 return -1; // no space
70 * The standard strncpy() function does not guarantee that the resulting string is null terminated.
71 * char ntbs[NTBS_SIZE];
72 * strncpy(ntbs, source, sizeof(ntbs)-1);
73 * ntbs[sizeof(ntbs)-1] = '\0'
76 char *s_strncpy(char *dest, const char *source, size_t n) {
80 while(n && (*dest++ = *source++)) {