Blob Blame History Raw
--- less-436/filename.c	2009-07-06 22:52:23.000000000 +0200
+++ less-436_vvitek/filename.c	2010-12-08 16:01:41.269695932 +0100
@@ -879,17 +879,32 @@ open_altfile(filename, pf, pfd)
 		 */
 		f = fileno(fd);
 		SET_BINARY(f);
+		*pfd = (void *) fd;
+		*pf = f;
 		if (read(f, &c, 1) != 1)
 		{
 			/*
-			 * Pipe is empty.  This means there is no alt file.
+			 * Error or pipe is empty. Close it and
+			 * check exit status of the pipe process.
 			 */
-			pclose(fd);
+			if (pclose(fd) == 0) {
+				/*
+				 * Exit status was zero, so the EOF was correct
+				 * empty output. Let the program open /dev/null
+				 * instead, as the pipe is already closed.
+				 * Set force_open to omit bad_file() check
+				 * failure, as it is special 'c' pseudo-device.
+				 */
+				*pf = 0;
+				*pfd = NULL;
+				force_open = 1;
+				return (save("/dev/null"));
+			}
+			*pf = 0;
+			*pfd = NULL;
 			return (NULL);
 		}
 		ch_ungetchar(c);
-		*pfd = (void *) fd;
-		*pf = f;
 		return (save("-"));
 	}
 #endif