From 0d2d9dc91e33ca8d3b10995479be8ebd98ea8c33 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Sun, 6 Oct 2024 12:27:04 +0200 Subject: [PATCH] Only add C files in directory load --- src/file.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/file.c b/src/file.c index 61843ee..9593381 100644 --- a/src/file.c +++ b/src/file.c @@ -131,20 +131,24 @@ static int file_load_ftw(const char *pathname, FILE *fd; char *content = NULL; if (type == FTW_F) { - content = file_load(pathname); - if (content == NULL) { - _err("Error: file_load %s",pathname); - return -1; - } - if (full_content == NULL) { - full_content = content; - } else { - full_content = realloc(full_content, strlen(full_content) + strlen(content) + 1); - if (full_content == NULL) { - _err("Error: realloc full_content"); + size_t pathlen = strlen(pathname); + if (pathname[pathlen-1] == 'c' && + pathname[pathlen-2] == '.') { + content = file_load(pathname); + if (content == NULL) { + _err("Error: file_load %s",pathname); return -1; } - strcat(full_content, content); + if (full_content == NULL) { + full_content = content; + } else { + full_content = realloc(full_content, strlen(full_content) + strlen(content) + 1); + if (full_content == NULL) { + _err("Error: realloc full_content"); + return -1; + } + strcat(full_content, content); + } } } return 0;