]> granicus.if.org Git - file/commitdiff
better handling of stdin
authorChristos Zoulas <christos@zoulas.com>
Wed, 26 Mar 2003 16:31:19 +0000 (16:31 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 26 Mar 2003 16:31:19 +0000 (16:31 +0000)
src/file.c
src/fsmagic.c

index 9ffdfe60fc60b19de446590fb0351699801cfa90..da96300352edac7186c18873ec28c014159a3660 100644 (file)
@@ -72,7 +72,7 @@
 #include "patchlevel.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$Id: file.c,v 1.74 2003/03/26 15:35:30 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.75 2003/03/26 16:31:19 christos Exp $")
 #endif /* lint */
 
 
@@ -364,12 +364,13 @@ private void
 process(const char *inname, int wid)
 {
        const char *type;
+       int std_in = strcmp(inname, "-") == 0;
 
        if (wid > 0 && !bflag)
-               (void) printf("%s%c%*s ", inname, separator,
-                   (int) (nopad ? 0 : (wid - strlen(inname))), "");
+               (void) printf("%s%c%*s ", std_in ? "/dev/stdin" : inname,
+                   separator, (int) (nopad ? 0 : (wid - strlen(inname))), "");
 
-       type = magic_file(magic, strcmp(inname, "-") == 0 ? NULL : inname);
+       type = magic_file(magic, std_in ? NULL : inname);
        if (type == NULL)
                printf("ERROR: %s\n", magic_error(magic));
        else
index 73e1bfeccc983bfffac03c0cadf425e517f6f9d0..bde658239a8682502410eba1c06b5e457b1c929e 100644 (file)
@@ -62,7 +62,7 @@
 #undef HAVE_MAJOR
 
 #ifndef        lint
-FILE_RCSID("@(#)$Id: fsmagic.c,v 1.38 2003/03/23 21:16:26 christos Exp $")
+FILE_RCSID("@(#)$Id: fsmagic.c,v 1.39 2003/03/26 16:31:20 christos Exp $")
 #endif /* lint */
 
 protected int
@@ -70,6 +70,9 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 {
        int ret = 0;
 
+       if (fn == NULL)
+               return 0;
+
        /*
         * Fstat is cheaper but fails for files you don't have read perms on.
         * On 4.2BSD and similar systems, use lstat() to identify symlinks.