if (io_testflag(stream, _IOREADING)) {
/* (void) fseek(stream, 0L, SEEK_CUR); */
int adjust = 0;
+ if (io_testflag(stream, _IOFIFO)) {
+ /* Can't seek in a pipe. */
+ return 0;
+ }
if (stream->_buf && !io_testflag(stream,_IONBF))
adjust = -stream->_count;
stream->_count = 0;
#include <stdio.h>
#include <stdlib.h>
#include "loc_incl.h"
+#include <sys/stat.h>
#define PMODE 0666
register int i;
int rwmode = 0, rwflags = 0;
FILE *stream;
+ struct stat st;
int fd, flags = 0;
for (i = 0; __iotab[i] != 0 ; i++)
if (fd < 0) return (FILE *)NULL;
+ if ( fstat( fd, &st ) < 0 ) {
+ _close(fd);
+ return (FILE *)NULL;
+ }
+
+ if ( st.st_mode & S_IFIFO ) flags |= _IOFIFO;
+
if (( stream = (FILE *) malloc(sizeof(FILE))) == NULL ) {
_close(fd);
return (FILE *)NULL;
#include <stdio.h>
#include <stdlib.h>
#include "loc_incl.h"
+#include <sys/stat.h>
#define PMODE 0666
freopen(const char *name, const char *mode, FILE *stream)
{
register int i;
+ struct stat st;
int rwmode = 0, rwflags = 0;
int fd, flags = stream->_flags & (_IONBF | _IOFBF | _IOLBF | _IOMYBUF);
rwflags |= O_APPEND | O_CREAT;
break;
default:
- return (FILE *)NULL;
+ goto loser;
}
while (*mode) {
}
if (fd < 0) {
- for( i = 0; i < FOPEN_MAX; i++) {
- if (stream == __iotab[i]) {
- __iotab[i] = 0;
- break;
- }
- }
- if (stream != stdin && stream != stdout && stream != stderr)
- free((void *)stream);
- return (FILE *)NULL;
+ goto loser;
}
+ if ( fstat( fd, &st ) == 0 ) {
+ if ( st.st_mode & S_IFIFO ) flags |= _IOFIFO;
+ } else {
+ goto loser;
+ }
+
stream->_count = 0;
stream->_fd = fd;
stream->_flags = flags;
return stream;
+
+loser:
+ for( i = 0; i < FOPEN_MAX; i++) {
+ if (stream == __iotab[i]) {
+ __iotab[i] = 0;
+ break;
+ }
+ }
+ if (stream != stdin && stream != stdout && stream != stderr)
+ free((void *)stream);
+ return (FILE *)NULL;
}