mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-15 10:18:39 -09:00
Let has_cachedir_tag use malloc instead of a buffer on the stack.
This commit is contained in:
parent
2784d82a9e
commit
1b1982e9af
1 changed files with 11 additions and 4 deletions
|
|
@ -104,16 +104,23 @@ void exclude_clear() {
|
||||||
* Exclusion of directories that contain only cached information.
|
* Exclusion of directories that contain only cached information.
|
||||||
* See http://www.brynosaurus.com/cachedir/
|
* See http://www.brynosaurus.com/cachedir/
|
||||||
*/
|
*/
|
||||||
|
#define CACHEDIR_TAG_FILENAME "CACHEDIR.TAG"
|
||||||
#define CACHEDIR_TAG_SIGNATURE "Signature: 8a477f597d28d172789f06886806bc55"
|
#define CACHEDIR_TAG_SIGNATURE "Signature: 8a477f597d28d172789f06886806bc55"
|
||||||
|
|
||||||
int has_cachedir_tag(const char *name) {
|
int has_cachedir_tag(const char *name) {
|
||||||
char buf[1024];
|
int path_l;
|
||||||
|
char *path;
|
||||||
|
const int signature_l = sizeof CACHEDIR_TAG_SIGNATURE - 1;
|
||||||
|
char buf[signature_l];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int match = 0;
|
int match = 0;
|
||||||
const int signature_l = sizeof CACHEDIR_TAG_SIGNATURE - 1;
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/CACHEDIR.TAG", name);
|
path_l = strlen(name) + sizeof CACHEDIR_TAG_FILENAME + 2;
|
||||||
f = fopen(buf, "rb");
|
path = malloc(path_l);
|
||||||
|
snprintf(path, path_l, "%s/%s", name, CACHEDIR_TAG_FILENAME);
|
||||||
|
f = fopen(path, "rb");
|
||||||
|
free(path);
|
||||||
|
|
||||||
if(f != NULL) {
|
if(f != NULL) {
|
||||||
match = ((fread(buf, 1, signature_l, f) == signature_l) &&
|
match = ((fread(buf, 1, signature_l, f) == signature_l) &&
|
||||||
!memcmp(buf, CACHEDIR_TAG_SIGNATURE, signature_l));
|
!memcmp(buf, CACHEDIR_TAG_SIGNATURE, signature_l));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue