commit 5f342330fa88a004405529545bbccc1dbb6ff940
parent 112a422351cd514eec59325483112edc737f43b6
Author: Paco Esteban <paco@e1e0.net>
Date: Mon, 22 Jun 2020 20:37:23 +0200
remove src_path[PATH_MAX] and work with pointers
I had to re-work articleq_free because I was getting a segfault.
Using a while loop as on queue(3)'s example and removing from head
instead of use SLIST_FOREACH and remove in place fixed the issue.
Diffstat:
M | ssnail.c | | | 28 | +++++++++++++++------------- |
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/ssnail.c b/ssnail.c
@@ -36,8 +36,8 @@ struct article {
size_t htmlz;
size_t origz;
- char src_path[PATH_MAX];
- char dst_path[PATH_MAX];
+ char *src_path;
+ char *dst_path;
char *orig_content;
char *html_content;
char *title;
@@ -243,8 +243,11 @@ articleq_free(struct listhead *h)
{
struct article *a;
- SLIST_FOREACH(a, h, entries) {
- SLIST_REMOVE(h, a, article, entries);
+ while (!SLIST_EMPTY(h)) {
+ a = SLIST_FIRST(h);
+ SLIST_REMOVE_HEAD(h, entries);
+ free(a->src_path);
+ free(a->dst_path);
free(a->orig_content);
free(a->html_content);
free(a->title);
@@ -439,25 +442,24 @@ process_dir(char *src, char *dst, int force)
if (dp->d_type == DT_REG) {
if (strcmp(get_filename_ext(src_path), "md") == 0) {
- char *fbuf = NULL;
- int n = 0;
-
a = malloc(sizeof(struct article));
if (a == NULL) {
error = ssnail_error_from_errno("malloc a");
goto out;
}
- n = strlcpy(a->src_path, src_path, PATH_MAX);
- if (n >= PATH_MAX) {
- error = ssnail_error_msg(2, "src_path cpy");
+ a->src_path = strndup(src_path, PATH_MAX);
+ if (a->src_path == NULL) {
+ error = ssnail_error_from_errno("malloc str_path");
goto out;
}
+ char *fbuf = NULL;
fbuf = str_rep(dst_path, ".md", ".html");
- n = strlcpy(a->dst_path, fbuf, PATH_MAX);
- if (n >= PATH_MAX) {
- error = ssnail_error_msg(2, "dst_path cpy");
+
+ a->dst_path = strndup(fbuf, PATH_MAX);
+ if (a->dst_path == NULL) {
+ error = ssnail_error_from_errno("malloc dst_path");
free(fbuf);
goto out;
}