diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2012-05-15 15:44:50 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2012-05-15 15:44:50 -0700 |
commit | f466203a93088fd437b5ba8873e343a85d7bd7d5 (patch) | |
tree | 0cedf3986a81c42052df2af244d19032d54c9c3f | |
parent | e6ed5f9eb80d5df417f538e27270fe9b61db35e4 (diff) | |
download | klibc-f466203a93088fd437b5ba8873e343a85d7bd7d5.tar.gz |
[klibc] Don't set the file pointer to -1 if unseekable
For unseekable files, don't set the file pointer to -1. Although
it is arguably meaningless anyway, there might be problems with having
the stdio file pointer be negative.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r-- | usr/klibc/stdio/fdopen.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/usr/klibc/stdio/fdopen.c b/usr/klibc/stdio/fdopen.c index a12efe5d5b1b1..e4226e9b0145a 100644 --- a/usr/klibc/stdio/fdopen.c +++ b/usr/klibc/stdio/fdopen.c @@ -21,6 +21,7 @@ FILE *fdopen(int fd, const char *mode) const size_t bufoffs = (sizeof *f + 4*sizeof(void *) - 1) & ~(4*sizeof(void *) - 1); + off_t pos; (void)mode; @@ -30,7 +31,8 @@ FILE *fdopen(int fd, const char *mode) f->data = f->buf = (char *)f + bufoffs; f->pub._io_fileno = fd; - f->pub._io_filepos = lseek(fd, 0, SEEK_CUR); + pos = lseek(fd, 0, SEEK_CUR); + f->pub._io_filepos = (pos >= 0) ? pos : 0; f->bufsiz = BUFSIZ; f->bufmode = isatty(fd) ? _IOLBF : _IOFBF; |