. use proper S_ISFIFO for ISFIFO check
. ignore ESPIPE error from lseek() in fflush() on read streams (because fifo's aren't detected when stdin, stdout or stderr)
This commit is contained in:
parent
17f48fc972
commit
a3bda44a41
3 changed files with 6 additions and 3 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "loc_incl.h"
|
||||
|
||||
ssize_t _write(int d, const char *buf, size_t nbytes);
|
||||
|
@ -36,10 +37,12 @@ fflush(FILE *stream)
|
|||
if (stream->_buf && !io_testflag(stream,_IONBF))
|
||||
adjust = -stream->_count;
|
||||
stream->_count = 0;
|
||||
if (_lseek(fileno(stream), (off_t) adjust, SEEK_CUR) == -1) {
|
||||
if (_lseek(fileno(stream), (off_t) adjust, SEEK_CUR) == -1 &&
|
||||
errno != ESPIPE) {
|
||||
stream->_flags |= _IOERR;
|
||||
return EOF;
|
||||
}
|
||||
errno = 0;
|
||||
if (io_testflag(stream, _IOWRITE))
|
||||
stream->_flags &= ~(_IOREADING | _IOWRITING);
|
||||
stream->_ptr = stream->_buf;
|
||||
|
|
|
@ -110,7 +110,7 @@ fopen(const char *name, const char *mode)
|
|||
return (FILE *)NULL;
|
||||
}
|
||||
|
||||
if ( st.st_mode & S_IFIFO ) flags |= _IOFIFO;
|
||||
if ( S_ISFIFO(st.st_mode) ) flags |= _IOFIFO;
|
||||
|
||||
if (( stream = (FILE *) malloc(sizeof(FILE))) == NULL ) {
|
||||
_close(fd);
|
||||
|
|
|
@ -87,7 +87,7 @@ freopen(const char *name, const char *mode, FILE *stream)
|
|||
}
|
||||
|
||||
if ( fstat( fd, &st ) == 0 ) {
|
||||
if ( st.st_mode & S_IFIFO ) flags |= _IOFIFO;
|
||||
if ( S_ISFIFO(st.st_mode) ) flags |= _IOFIFO;
|
||||
} else {
|
||||
goto loser;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue