[BACK]Return to fsmagic.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / file

Diff for /src/usr.bin/file/Attic/fsmagic.c between version 1.12 and 1.13

version 1.12, 2008/05/08 01:40:56 version 1.13, 2009/04/24 18:54:34
Line 61 
Line 61 
 FILE_RCSID("@(#)$Id$")  FILE_RCSID("@(#)$Id$")
 #endif  /* lint */  #endif  /* lint */
   
   private int
   bad_link(struct magic_set *ms, int err, char *buf)
   {
           char *errfmt;
           if (err == ELOOP)
                   errfmt = "symbolic link in a loop";
           else
                   errfmt = "broken symbolic link to `%s'";
           if (ms->flags & MAGIC_ERROR) {
                   file_error(ms, err, errfmt, buf);
                   return -1;
           }
           if (file_printf(ms, errfmt, buf) == -1)
                   return -1;
           return 1;
   }
   
 protected int  protected int
 file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)  file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 {  {
         int ret = 0;          int ret = 0;
           int mime = ms->flags & MAGIC_MIME;
 #ifdef  S_IFLNK  #ifdef  S_IFLNK
         char buf[BUFSIZ+4];          char buf[BUFSIZ+4];
         int nch;          int nch;
Line 96 
Line 114 
                 return 1;                  return 1;
         }          }
   
         if ((ms->flags & MAGIC_MIME) != 0) {          if (mime) {
                 if ((sb->st_mode & S_IFMT) != S_IFREG) {                  if ((sb->st_mode & S_IFMT) != S_IFREG) {
                         if (file_printf(ms, "application/x-not-regular-file")                          if ((mime & MAGIC_MIME_TYPE) &&
                               file_printf(ms, "application/x-not-regular-file")
                             == -1)                              == -1)
                                 return -1;                                      return -1;
                         return 1;                          return 1;
                 }                  }
         }          }
Line 136 
Line 155 
                  */                   */
                 if ((ms->flags & MAGIC_DEVICES) != 0)                  if ((ms->flags & MAGIC_DEVICES) != 0)
                         break;                          break;
 #ifdef HAVE_ST_RDEV  #ifdef HAVE_STAT_ST_RDEV
 # ifdef dv_unit  # ifdef dv_unit
                 if (file_printf(ms, "character special (%d/%d/%d)",                  if (file_printf(ms, "character special (%d/%d/%d)",
                     major(sb->st_rdev), dv_unit(sb->st_rdev),                      major(sb->st_rdev), dv_unit(sb->st_rdev),
Line 162 
Line 181 
                  */                   */
                 if ((ms->flags & MAGIC_DEVICES) != 0)                  if ((ms->flags & MAGIC_DEVICES) != 0)
                         break;                          break;
 #ifdef HAVE_ST_RDEV  #ifdef HAVE_STAT_ST_RDEV
 # ifdef dv_unit  # ifdef dv_unit
                 if (file_printf(ms, "block special (%d/%d/%d)",                  if (file_printf(ms, "block special (%d/%d/%d)",
                     major(sb->st_rdev), dv_unit(sb->st_rdev),                      major(sb->st_rdev), dv_unit(sb->st_rdev),
Line 208 
Line 227 
                                 return -1;                                  return -1;
                         return 1;                          return 1;
                 }                  }
                 buf[nch] = '\0';        /* readlink(2) forgets this */                  buf[nch] = '\0';        /* readlink(2) does not do this */
   
                 /* If broken symlink, say so and quit early. */                  /* If broken symlink, say so and quit early. */
                 if (*buf == '/') {                  if (*buf == '/') {
                     if (stat(buf, &tstatbuf) < 0) {                          if (stat(buf, &tstatbuf) < 0)
                             if (ms->flags & MAGIC_ERROR) {                                  return bad_link(ms, errno, buf);
                                     file_error(ms, errno,                  } else {
                                         "broken symbolic link to `%s'", buf);  
                                     return -1;  
                             }  
                             if (file_printf(ms, "broken symbolic link to `%s'",  
                                 buf) == -1)  
                                     return -1;  
                             return 1;  
                     }  
                 }  
                 else {  
                         char *tmp;                          char *tmp;
                         char buf2[BUFSIZ+BUFSIZ+4];                          char buf2[BUFSIZ+BUFSIZ+4];
   
Line 247 
Line 256 
                                 (void)strlcat(buf2, buf, sizeof buf2); /* plus (rel) link */                                  (void)strlcat(buf2, buf, sizeof buf2); /* plus (rel) link */
                                 tmp = buf2;                                  tmp = buf2;
                         }                          }
                         if (stat(tmp, &tstatbuf) < 0) {                          if (stat(tmp, &tstatbuf) < 0)
                                 if (ms->flags & MAGIC_ERROR) {                                  return bad_link(ms, errno, buf);
                                         file_error(ms, errno,  
                                             "broken symbolic link to `%s'",  
                                             buf);  
                                         return -1;  
                                 }  
                                 if (file_printf(ms,  
                                     "broken symbolic link to `%s'", buf) == -1)  
                                         return -1;  
                                 return 1;  
                         }  
                 }                  }
   
                 /* Otherwise, handle it. */                  /* Otherwise, handle it. */
Line 304 
Line 303 
          * when we read the file.)           * when we read the file.)
          */           */
         if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {          if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
                 if (file_printf(ms, (ms->flags & MAGIC_MIME) ?                  if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
                     "application/x-empty" : "empty") == -1)                      file_printf(ms, mime ? "application/x-empty" :
                       "empty") == -1)
                         return -1;                          return -1;
                 return 1;                  return 1;
         }          }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13