Skip to content

Commit

Permalink
Only add C files in directory load
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinux committed Oct 6, 2024
1 parent 3eb54b9 commit 3887d98
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 150 in src/file.c

View workflow job for this annotation

GitHub Actions / 🚨 C lint

[cpplint] reported by reviewdog 🐶 Almost always, snprintf is better than strcat [runtime/printf] [4] Raw Output: src/file.c:150: Almost always, snprintf is better than strcat [runtime/printf] [4]
}
}
}
return 0;
Expand Down

0 comments on commit 3887d98

Please sign in to comment.