Blob Blame History Raw
diff --git a/src/fsmagic.c b/src/fsmagic.c
index 7200271..1ffe667 100644
--- a/src/fsmagic.c
+++ b/src/fsmagic.c
@@ -124,14 +124,12 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 
 	if (ret) {
 		if (ms->flags & MAGIC_ERROR) {
-			file_error(ms, errno, "cannot stat `%s'", fn);
+			file_error(ms, errno, "cannot stat");
 			return -1;
 		}
-		if (file_printf(ms, "cannot open `%s' (%s)",
-		    fn, strerror(errno)) == -1)
+		if (file_printf(ms, "cannot open (%s)", strerror(errno)) == -1)
 			return -1;
-		ms->event_flags |= EVENT_HAD_ERR;
-		return -1;
+		return 0;
 	}
 
 	if (!mime) {
diff --git a/src/magic.c b/src/magic.c
index 2b61080..a184a35 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -417,8 +417,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 			ispipe = 1;
 	} else {
 		int flags = O_RDONLY|O_BINARY;
+		int okstat = stat(inname, &sb) == 0;
 
-		if (stat(inname, &sb) == 0 && S_ISFIFO(sb.st_mode)) {
+		if (okstat && S_ISFIFO(sb.st_mode)) {
 #ifdef O_NONBLOCK
 			flags |= O_NONBLOCK;
 #endif
@@ -427,7 +428,8 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 
 		errno = 0;
 		if ((fd = open(inname, flags)) < 0) {
-			if (unreadable_info(ms, sb.st_mode, inname) == -1)
+			if (okstat &&
+			    unreadable_info(ms, sb.st_mode, inname) == -1)
 				goto done;
 			rv = 0;
 			goto done;
@@ -462,7 +464,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 
 	} else {
 		if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
-			file_error(ms, errno, "cannot read `%s'", inname);
+			file_error(ms, errno, "cannot read");
 			goto done;
 		}
 	}