From 2784d82a9e2c0712da156f30fcda80bb8060ffd9 Mon Sep 17 00:00:00 2001
From: Petr Pudlak <petr.mvd@gmail.com>
Date: Fri, 12 Apr 2013 14:53:33 +0200
Subject: [PATCH] CACHEDIR.TAG - improve code style and the name of the
 parameter.

Use a macro instead of the global constant `cachedir_tag_signature`.
Use `memcmp` instead of `strncmp`.
Add `has_cachedir_tag` to exclude.h.

(See http://dev.yorhel.nl/ncdu/bug/30)
---
 src/exclude.c | 29 ++++++++++++++---------------
 src/exclude.h |  1 +
 src/main.c    |  4 ++--
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/exclude.c b/src/exclude.c
index d7b679d..97975c0 100644
--- a/src/exclude.c
+++ b/src/exclude.c
@@ -104,21 +104,20 @@ void exclude_clear() {
  * Exclusion of directories that contain only cached information.
  * See http://www.brynosaurus.com/cachedir/
  */
-static const char cachedir_tag_signature[] =
-    "Signature: 8a477f597d28d172789f06886806bc55";
+#define CACHEDIR_TAG_SIGNATURE "Signature: 8a477f597d28d172789f06886806bc55"
 
 int has_cachedir_tag(const char *name) {
-    char buf[1024];
-    FILE *f;
-    int match = 0;
-    const int signature_l = strlen(cachedir_tag_signature);
-
-    snprintf(buf, sizeof(buf), "%s/CACHEDIR.TAG", name);
-    f = fopen(buf, "rb");
-    if (f != NULL) {
-        match = ((fread(buf, 1, signature_l, f) == signature_l) &&
-                    !strncmp(buf, cachedir_tag_signature, signature_l));
-        fclose(f);
-    }
-    return match;
+  char buf[1024];
+  FILE *f;
+  int match = 0;
+  const int signature_l = sizeof CACHEDIR_TAG_SIGNATURE - 1;
+
+  snprintf(buf, sizeof(buf), "%s/CACHEDIR.TAG", name);
+  f = fopen(buf, "rb");
+  if(f != NULL) {
+    match = ((fread(buf, 1, signature_l, f) == signature_l) &&
+                !memcmp(buf, CACHEDIR_TAG_SIGNATURE, signature_l));
+    fclose(f);
+  }
+  return match;
 }
diff --git a/src/exclude.h b/src/exclude.h
index d3516b6..2064466 100644
--- a/src/exclude.h
+++ b/src/exclude.h
@@ -30,5 +30,6 @@ void exclude_add(char *);
 int  exclude_addfile(char *);
 int  exclude_match(char *);
 void exclude_clear();
+int  has_cachedir_tag(const char *name);
 
 #endif
diff --git a/src/main.c b/src/main.c
index 54771b2..6084edc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -126,7 +126,7 @@ static void argv_parse(int argc, char **argv) {
     { '2', 0, "-2" },
     {  1,  1, "--exclude" },
     { 'X', 1, "-X,--exclude-from" },
-    { 'C', 0, "-C,--cachedir-tag" },
+    { 'C', 0, "--exclude-caches" },
     {0,0,NULL}
   };
 
@@ -148,7 +148,7 @@ static void argv_parse(int argc, char **argv) {
       printf("  -0,-1,-2                   UI to use when scanning (0=none,2=full ncurses)\n");
       printf("  --exclude PATTERN          Exclude files that match PATTERN\n");
       printf("  -X, --exclude-from FILE    Exclude files that match any pattern in FILE\n");
-      printf("  -C, --cachedir-tag         Exclude directories containing CACHEDIR.TAG\n");
+      printf("  --exclude-caches           Exclude directories containing CACHEDIR.TAG\n");
       exit(0);
     case 'q': update_delay = 2000; break;
     case 'v':
-- 
GitLab