]> granicus.if.org Git - file/commitdiff
PR/191: Look in $HOME/.magic.mgc too
authorChristos Zoulas <christos@zoulas.com>
Sun, 26 Aug 2012 11:00:58 +0000 (11:00 +0000)
committerChristos Zoulas <christos@zoulas.com>
Sun, 26 Aug 2012 11:00:58 +0000 (11:00 +0000)
src/magic.c

index 7eb0441b102583519a038c98c22a853262b7198e..2b610809662e0e7f3b83b4eb8cb55e71ec4b3c2f 100644 (file)
@@ -33,7 +33,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: magic.c,v 1.73 2011/05/10 17:08:14 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.74 2011/05/26 01:27:59 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -101,16 +101,21 @@ get_default_magic(void)
        if ((home = getenv("HOME")) == NULL)
                return MAGIC;
 
-       if (asprintf(&hmagicpath, "%s/.magic", home) < 0)
+       if (asprintf(&hmagicpath, "%s/.magic.mgc", home) < 0)
                return MAGIC;
-       if (stat(hmagicpath, &st) == -1)
-               goto out;
-       if (S_ISDIR(st.st_mode)) {
+       if (stat(hmagicpath, &st) == -1) {
                free(hmagicpath);
-               if (asprintf(&hmagicpath, "%s/%s", home, hmagic) < 0)
+               if (asprintf(&hmagicpath, "%s/.magic", home) < 0)
                        return MAGIC;
-               if (access(hmagicpath, R_OK) == -1)
+               if (stat(hmagicpath, &st) == -1)
                        goto out;
+               if (S_ISDIR(st.st_mode)) {
+                       free(hmagicpath);
+                       if (asprintf(&hmagicpath, "%s/%s", home, hmagic) < 0)
+                               return MAGIC;
+                       if (access(hmagicpath, R_OK) == -1)
+                               goto out;
+               }
        }
 
        if (asprintf(&default_magic, "%s:%s", hmagicpath, MAGIC) < 0)