if (sub_len>str_len) return 0;
return streq(str+str_len-sub_len, sub);
}
+
+PUBLIC_FN char **buf_to_linearray(char *buf, ssize_t buflen) {
+ if (buflen == -1) buflen = strlen(buf);
+ size_t linecount = count_char_occurences_in_buf(buf, buflen, '\n')+1;
+ char **ret = malloc(linecount * sizeof(char*) + 1);
+ ret[linecount] = NULL;
+ if (ret == NULL) return NULL;
+ char **r = ret;
+ *(r++) = buf; /* first line starts at byte zero */
+ char *b = buf;
+ char *be = buf+buflen;
+ while (b<be) {
+ if (*b == '\n') {
+ *b = '\0';
+ *(r++) = b+1;
+ }
+ b++;
+ }
+ return ret;
+}