From: Christos Zoulas Date: Wed, 26 Mar 2003 16:31:19 +0000 (+0000) Subject: better handling of stdin X-Git-Tag: FILE4_01~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=abf22bbdd6e1beb911f4eef004ce15e98545c614;p=file better handling of stdin --- diff --git a/src/file.c b/src/file.c index 9ffdfe60..da963003 100644 --- a/src/file.c +++ b/src/file.c @@ -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 diff --git a/src/fsmagic.c b/src/fsmagic.c index 73e1bfec..bde65823 100644 --- a/src/fsmagic.c +++ b/src/fsmagic.c @@ -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.