aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-05-08 17:42:08 -0700
committerH. Peter Anvin <hpa@zytor.com>2012-05-08 17:48:21 -0700
commit96819e548a603081a482bfb71ac0c71051a9021b (patch)
treea47c31f38a737ee00ba4115f50281010c6f77e6b
parent8254a21514d5dfbcec248da334441264570e801b (diff)
downloadklibc-96819e548a603081a482bfb71ac0c71051a9021b.tar.gz
[klibc] Replace the stdio offset with a stdio data pointer
There are almost no places where the offset is the useful piece, so replace the offset with a data pointer. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--usr/include/stdio.h7
-rw-r--r--usr/klibc/stdio/fflush.c2
-rw-r--r--usr/klibc/stdio/fread.c8
-rw-r--r--usr/klibc/stdio/fxopen.c4
-rw-r--r--usr/klibc/stdio/ungetc.c4
5 files changed, 10 insertions, 15 deletions
diff --git a/usr/include/stdio.h b/usr/include/stdio.h
index ea775006974a4..8dc178e19e86f 100644
--- a/usr/include/stdio.h
+++ b/usr/include/stdio.h
@@ -11,17 +11,12 @@
#include <stddef.h>
#include <unistd.h>
-/* Unidirectional buffer */
-struct _IO_buf {
- char *buf; /* Actual buffer */
-};
-
/* Actual FILE structure */
struct _IO_file {
struct _IO_file *prev, *next;
off_t filepos; /* File position */
char *buf; /* Buffer */
- int offset; /* Offset to data in buffer */
+ char *data; /* Data in buffer */
int bytes; /* Data bytes in buffer */
int bufsiz; /* Total size of buffer */
int fd; /* Underlying file descriptor */
diff --git a/usr/klibc/stdio/fflush.c b/usr/klibc/stdio/fflush.c
index 0970c68a678ef..8c78be4720eec 100644
--- a/usr/klibc/stdio/fflush.c
+++ b/usr/klibc/stdio/fflush.c
@@ -38,7 +38,7 @@ int fflush(FILE *f)
p += rv;
f->bytes -= rv;
}
- f->offset = _IO_UNGET_SLOP;
+ f->data = f->buf + _IO_UNGET_SLOP;
f->flags &= ~_IO_FILE_FLAG_WRITE;
return 0;
diff --git a/usr/klibc/stdio/fread.c b/usr/klibc/stdio/fread.c
index b318dac506ad6..6eecfc0da0b6f 100644
--- a/usr/klibc/stdio/fread.c
+++ b/usr/klibc/stdio/fread.c
@@ -18,8 +18,8 @@ size_t _fread(void *buf, size_t count, FILE *f)
nb = f->bytes;
nb = (count < nb) ? count : nb;
if (nb) {
- memcpy(p, f->buf+f->offset, nb);
- f->offset += nb;
+ memcpy(p, f->data, nb);
+ f->data += nb;
f->bytes -= nb;
p += nb;
count -= nb;
@@ -33,9 +33,9 @@ size_t _fread(void *buf, size_t count, FILE *f)
break; /* Done... */
/* If we get here, f->ibuf must be empty */
- f->offset = _IO_UNGET_SLOP;
+ f->data = f->buf + _IO_UNGET_SLOP;
- rv = read(f->fd, f->buf+_IO_UNGET_SLOP, BUFSIZ);
+ rv = read(f->fd, f->data, BUFSIZ);
if (rv == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;
diff --git a/usr/klibc/stdio/fxopen.c b/usr/klibc/stdio/fxopen.c
index 7c596ec0da925..5f9d61d1d6edc 100644
--- a/usr/klibc/stdio/fxopen.c
+++ b/usr/klibc/stdio/fxopen.c
@@ -60,8 +60,8 @@ FILE *__fxopen(int fd, int flags, int close_on_err)
goto err;
f->bufsiz = BUFSIZ;
- f->offset = _IO_UNGET_SLOP;
- f->bytes = 0; /* No bytes in buffer */
+ f->data = f->buf + _IO_UNGET_SLOP;
+ f->bytes = 0; /* No data in buffer */
f->flags = isatty(fd) ? _IO_FILE_FLAG_LINE_BUF : 0;
/* Insert into linked list */
diff --git a/usr/klibc/stdio/ungetc.c b/usr/klibc/stdio/ungetc.c
index b2a304cdfb803..f8ed58dffa1aa 100644
--- a/usr/klibc/stdio/ungetc.c
+++ b/usr/klibc/stdio/ungetc.c
@@ -6,10 +6,10 @@
int ungetc(int c, FILE *f)
{
- if (f->flags & _IO_FILE_FLAG_WRITE || f->offset <= 0)
+ if (f->flags & _IO_FILE_FLAG_WRITE || f->data <= f->buf)
return EOF;
- f->buf[--f->offset] = c;
+ *(--f->data) = c;
f->bytes++;
f->flags |= _IO_FILE_FLAG_READ;
return c;