From c29eb75789413c0b5a3816f0f535675317617f29 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Sun, 26 Aug 2012 10:21:37 +0000 Subject: [PATCH] PR/192: don't depend on FIONREAD if we are a pipe. --- src/compress.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/compress.c b/src/compress.c index 2b05352e..91c69a16 100644 --- a/src/compress.c +++ b/src/compress.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.67 2011/09/01 12:12:37 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.68 2011/12/08 12:38:24 rrt Exp $") #endif #include "magic.h" @@ -168,12 +168,9 @@ swrite(int fd, const void *buf, size_t n) * `safe' read for sockets and pipes. */ protected ssize_t -sread(int fd, void *buf, size_t n, int canbepipe __attribute__ ((unused))) +sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__))) { ssize_t rv; -#ifdef FD_ZERO - ssize_t cnt; -#endif #ifdef FIONREAD int t = 0; #endif @@ -183,8 +180,9 @@ sread(int fd, void *buf, size_t n, int canbepipe __attribute__ ((unused))) goto nocheck; #ifdef FIONREAD - if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) { + if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1 || t == 0)) { #ifdef FD_ZERO + ssize_t cnt; for (cnt = 0;; cnt++) { fd_set check; struct timeval tout = {0, 100 * 1000}; @@ -241,9 +239,6 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf, char buf[4096]; ssize_t r; int tfd; -#ifdef HAVE_MKSTEMP - int te; -#endif (void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof buf); #ifndef HAVE_MKSTEMP @@ -255,10 +250,13 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf, errno = r; } #else - tfd = mkstemp(buf); - te = errno; - (void)unlink(buf); - errno = te; + { + int te; + tfd = mkstemp(buf); + te = errno; + (void)unlink(buf); + errno = te; + } #endif if (tfd == -1) { file_error(ms, errno, -- 2.40.0