src/scanner.c

changeset 102
665b60727a89
parent 101
0cb645809b1a
child 103
31fa205db85a
--- a/src/scanner.c	Sat Jul 04 11:10:51 2026 +0200
+++ b/src/scanner.c	Sat Jul 04 12:09:37 2026 +0200
@@ -35,7 +35,7 @@
 #include <windows.h>
 #include <shlwapi.h>
 
-void get_working_dir(const char** out_ptr, size_t *out_len) {
+void get_working_dir(const char **out_ptr, size_t *out_len) {
   static char cwd[MAX_PATH];
   if (GetCurrentDirectoryA(MAX_PATH, cwd) == 0) {
     fprintf(stderr, "Could not get current working directory.\n");
@@ -57,7 +57,7 @@
 }
 #else
 #include <unistd.h>
-void get_working_dir(const char** out_ptr, size_t *out_len) {
+void get_working_dir(const char **out_ptr, size_t *out_len) {
   static char cwd[PATH_MAX];
   if (getcwd(cwd, sizeof(cwd)) == NULL) {
     fprintf(stderr, "Could not get current working directory.\n");
@@ -83,12 +83,12 @@
   char *displayname;
   unsigned displayname_len;
   char *filename;
-  char *ext;
+  const char *ext;
   unsigned st_mode;
   struct filelist *next;
 };
 
-static bool testSuffix(char* filename, string_list* list) {
+static bool testSuffix(const char *filename, string_list *list) {
   bool ret = false;
   size_t tokenlen, fnamelen = strlen(filename);
   for (size_t t = 0 ; t < list->count ; t++) {
@@ -104,8 +104,8 @@
   return ret;
 }
 
-static void addResultPerExtension(scanresult_ext* result,
-                                  char* ext, unsigned value) {
+static void addResultPerExtension(scanresult_ext *result,
+                                  const char *ext, unsigned value) {
   if (!result) return;
   
   if (!ext) ext = "w/o";
@@ -119,8 +119,8 @@
   
   if (result->count == result->capacity) {
     unsigned newcap = result->capacity+8;
-    char** extarr = realloc(result->extensions, newcap*sizeof(char*));
-    unsigned* resultarr = realloc(result->result, newcap*sizeof(unsigned));
+    char **extarr = realloc(result->extensions, newcap*sizeof(char*));
+    unsigned *resultarr = realloc(result->result, newcap*sizeof(unsigned));
     if (!extarr || !resultarr) {
       fprintf(stderr, "Memory allocation error.\n");
       abort();
@@ -135,15 +135,15 @@
   result->count++;
 }
 
-scanresult* new_scanresult(settings* settings) {
-  scanresult* result = calloc(1, sizeof(scanresult));
+scanresult *new_scanresult(settings *settings) {
+  scanresult *result = calloc(1, sizeof(scanresult));
   if (settings->individual_sums) {
     result->ext = calloc(1, sizeof(scanresult_ext));
   }
   return result;
 }
 
-void destroy_scanresult(scanresult* result) {
+void destroy_scanresult(scanresult *result) {
   if (result->ext) {
     if (result->ext->count > 0) {
       for (unsigned i = 0 ; i < result->ext->count ; i++) {
@@ -157,9 +157,9 @@
   free(result);
 }
 
-static struct filelist *buildFileList(scanner scanner, settings* settings) {
+static struct filelist *buildFileList(scanner scanner, settings *settings) {
 
-  struct filelist* list = NULL;
+  struct filelist *list = NULL;
   DIR *dirf;
   struct dirent *entry;
   struct stat statbuf;
@@ -186,7 +186,7 @@
       
       /* Construct full pathname string */
       size_t dirnamelen = strlen(scanner.dir);
-      char *filename = malloc(2+dirnamelen+newentry->displayname_len);
+      char *filename = malloc(2 + dirnamelen + newentry->displayname_len);
       memcpy(filename, scanner.dir, dirnamelen);
       if (filename[dirnamelen - 1] != settings->fileSeparator) {
         filename[dirnamelen++] = settings->fileSeparator;
@@ -233,7 +233,7 @@
   return list;
 }
 
-static bool is_dir_excluded(settings* settings, const char* dir) {
+static bool is_dir_excluded(settings *settings, const char *dir) {
   const string_list * const list = settings->excludeDirs;
 
   for (size_t i = 0 ; i < list->count ; i++) {
@@ -251,7 +251,7 @@
       }
     } else {
       /* compare the full paths */
-      char* absdir = make_path_absolute(dir);
+      char *absdir = make_path_absolute(dir);
       if (pathcmp(list->items[i], absdir) == 0) {
         free(absdir);
         return true;
@@ -262,8 +262,8 @@
   return false;
 }
 
-void scanDirectory(scanner scnr, settings* settings,
-    string_list* output, scanresult* result) {
+void scanDirectory(scanner scnr, settings *settings,
+    string_list *output, scanresult *result) {
 
   result->result = 0;
   bool bfile;
@@ -435,7 +435,7 @@
 #else
   static char fs = '/';
 #endif /* _WIN32 */
-  char* abspath;
+  char *abspath;
   if (path_is_relative(path)) {
     if (cwdlen == 0) {
       get_working_dir(&cwd, &cwdlen);
@@ -457,7 +457,7 @@
   }
   /* make path canonical */
   size_t abspathlen = strlen(abspath);
-  char* canonical = malloc(abspathlen + 1);
+  char *canonical = malloc(abspathlen + 1);
   size_t canonicallen = 0;
   for (size_t j = 0; j < abspathlen; j++) {
     canonical[canonicallen++] = abspath[j];

mercurial