]> granicus.if.org Git - file/commitdiff
Change info_from_stat to unreadable_info, using access to determine
authorReuben Thomas <rrt@sc3d.org>
Fri, 25 Jul 2008 23:30:32 +0000 (23:30 +0000)
committerReuben Thomas <rrt@sc3d.org>
Fri, 25 Jul 2008 23:30:32 +0000 (23:30 +0000)
information more accurately and comprehensibly.

src/magic.c

index 81320f992035a3fd8e8080859c8f3ce4c066bcd8..e7b002aa369371ffffae217dda9d5225690f8c55 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) Christos Zoulas 2003.
  * All Rights Reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -11,7 +11,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- *  
+ *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 #include "patchlevel.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: magic.c,v 1.52 2008/07/03 15:53:10 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.53 2008/07/16 18:00:57 christos Exp $")
 #endif /* lint */
 
-#ifndef PIPE_BUF 
+#ifndef PIPE_BUF
 /* Get the PIPE_BUF from pathconf */
 #ifdef _PC_PIPE_BUF
 #define PIPE_BUF pathconf(".", _PC_PIPE_BUF)
@@ -86,7 +86,7 @@ protected int file_os2_apptype(struct magic_set *ms, const char *fn,
 private void free_mlist(struct mlist *);
 private void close_and_restore(const struct magic_set *, const char *, int,
     const struct stat *);
-private int info_from_stat(struct magic_set *, mode_t);
+private int unreadable_info(struct magic_set *, mode_t, const char *);
 #ifndef COMPILE_ONLY
 private const char *file_or_fd(struct magic_set *, const char *, int);
 #endif
@@ -115,7 +115,7 @@ magic_open(int flags)
 
        if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL)
                goto free;
-       
+
        ms->haderr = 0;
        ms->error = -1;
        ms->mlist = NULL;
@@ -146,13 +146,13 @@ free_mlist(struct mlist *mlist)
 }
 
 private int
-info_from_stat(struct magic_set *ms, mode_t md)
+unreadable_info(struct magic_set *ms, mode_t md, const char *file)
 {
        /* We cannot open it, but we were able to stat it. */
-       if (md & 0222)
+       if (access(file, W_OK) == 0)
                if (file_printf(ms, "writable, ") == -1)
                        return -1;
-       if (md & 0111)
+       if (access(file, X_OK) == 0)
                if (file_printf(ms, "executable, ") == -1)
                        return -1;
        if (S_ISREG(md))
@@ -306,7 +306,13 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
                        (void)strcat(strcpy(tmp, inname), ".exe");
                        if ((fd = open(tmp, flags)) < 0) {
 #endif
-                               if (info_from_stat(ms, sb.st_mode) == -1)
+                               if (unreadable_info(ms, sb.st_mode,
+#ifdef __CYGWIN
+                                                   tmp
+#else
+                                                   inname
+#endif
+                                                   ) == -1)
                                        goto done;
                                rv = 0;
                                goto done;
@@ -336,7 +342,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 
                if (nbytes == 0) {
                        /* We can not read it, but we were able to stat it. */
-                       if (info_from_stat(ms, sb.st_mode) == -1)
+                       if (unreadable_info(ms, sb.st_mode, inname) == -1)
                                goto done;
                        rv = 0;
                        goto done;
@@ -367,7 +373,7 @@ magic_buffer(struct magic_set *ms, const void *buf, size_t nb)
                return NULL;
        /*
         * The main work is done here!
-        * We have the file name and/or the data buffer to be identified. 
+        * We have the file name and/or the data buffer to be identified.
         */
        if (file_buffer(ms, -1, NULL, buf, nb) == -1) {
                return NULL;