From 0e951a0f8831ac2885fe64531438eb28202f6e53 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Mon, 13 Nov 2023 05:30:27 +0100 Subject: Move to Chromium styleguide --- list.c | 89 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 45 insertions(+), 44 deletions(-) (limited to 'list.c') diff --git a/list.c b/list.c index 0743543..f958ea2 100644 --- a/list.c +++ b/list.c @@ -1,64 +1,65 @@ +#include #include #include -#include -#include #include +#include #include "list.h" -void add_file_path(Node **head, char *file_path) { - Node *new = (Node *)malloc(sizeof(Node)); - new->file_path = strdup(file_path); - new->next = *head; - *head = new; +void add_file_path(Node** head, char* file_path) { + Node* new = (Node*)malloc(sizeof(Node)); + new->file_path = strdup(file_path); + new->next = *head; + *head = new; } -void list_files_recursively(char *base_path, Node **head) { - char path[1000]; - struct dirent *dp; - DIR *dir = opendir(base_path); +void list_files_recursively(char* base_path, Node** head) { + char path[1000]; + struct dirent* dp; + DIR* dir = opendir(base_path); - if (!dir) return; + if (!dir) + return; - while ((dp = readdir(dir)) != NULL) { - if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0) { - strcpy(path, base_path); - strcat(path, "/"); - strcat(path, dp->d_name); + while ((dp = readdir(dir)) != NULL) { + if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0) { + strcpy(path, base_path); + strcat(path, "/"); + strcat(path, dp->d_name); - struct stat statbuf; - if (stat(path, &statbuf) != -1) { - if (S_ISDIR(statbuf.st_mode)) { - list_files_recursively(path, head); - } else { - add_file_path(head, path); - } - } - } - } + struct stat statbuf; + if (stat(path, &statbuf) != -1) { + if (S_ISDIR(statbuf.st_mode)) { + list_files_recursively(path, head); + } else { + add_file_path(head, path); + } + } + } + } - closedir(dir); + closedir(dir); } -void free_file_list(Node *head) { - Node *tmp; +void free_file_list(Node* head) { + Node* tmp; - while (head != NULL) { - tmp = head; - head = head->next; - free(tmp->file_path); - free(tmp); - } + while (head != NULL) { + tmp = head; + head = head->next; + free(tmp->file_path); + free(tmp); + } } -int size_of_file_list(Node *head) { - int count = 0; +int size_of_file_list(Node* head) { + int count = 0; - Node *current = head; - while (current != NULL) { - count++; - current = current->next; - } + Node* current = head; + while (current != NULL) { + count++; + current = current->next; + } - return count; + return count; } -- cgit v1.2.3