Skip to content
Snippets Groups Projects
Commit 2784d82a authored by Petr Pudlak's avatar Petr Pudlak
Browse files

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)
parent 3def47c3
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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
......@@ -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':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment