summaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-28 01:14:44 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-28 01:14:44 -0400
commite3cd6c5c265cd481db6e0c5b529855d99f0bda30 (patch)
tree85d2c586e4ea8e261ed68cc4b1901a1711774441 /src/internal
parentea343364a719add2cd8adf8a50c15bb5f9400dd8 (diff)
downloadmusl-e3cd6c5c265cd481db6e0c5b529855d99f0bda30.tar.gz
major stdio overhaul, using readv/writev, plus other changes
the biggest change in this commit is that stdio now uses readv to fill the caller's buffer and the FILE buffer with a single syscall, and likewise writev to flush the FILE buffer and write out the caller's buffer in a single syscall. making this change required fundamental architectural changes to stdio, so i also made a number of other improvements in the process: - the implementation no longer assumes that further io will fail following errors, and no longer blocks io when the error flag is set (though the latter could easily be changed back if desired) - unbuffered mode is no longer implemented as a one-byte buffer. as a consequence, scanf unreading has to use ungetc, to the unget buffer has been enlarged to hold at least 2 wide characters. - the FILE structure has been rearranged to maintain the locations of the fields that might be used in glibc getc/putc type macros, while shrinking the structure to save some space. - error cases for fflush, fseek, etc. should be more correct. - library-internal macros are used for getc_unlocked and putc_unlocked now, eliminating some ugly code duplication. __uflow and __overflow are no longer used anywhere but these macros. switch to read or write mode is also separated so the code can be better shared, e.g. with ungetc. - lots of other small things.
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/stdio_impl.h34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h
index b977df68..90a8214b 100644
--- a/src/internal/stdio_impl.h
+++ b/src/internal/stdio_impl.h
@@ -18,10 +18,11 @@
#include <sys/wait.h>
#include <math.h>
#include <float.h>
+#include <sys/uio.h>
#include "syscall.h"
#include "libc.h"
-#define UNGET 4
+#define UNGET 8
#define FLOCK(f) ((libc.lockfile && (f)->lock>=0) ? (libc.lockfile((f)),0) : 0)
#define FUNLOCK(f) ((f)->lockcount && (--(f)->lockcount || ((f)->lock=0)))
@@ -31,14 +32,18 @@
#define F_NOWR 8
#define F_EOF 16
#define F_ERR 32
+#define F_SVB 64
struct __FILE_s {
unsigned flags;
- unsigned char *rpos, *rstop;
- unsigned char *rend, *wend;
- unsigned char *wpos, *wstop;
+ unsigned char *rpos, *rend;
+ int (*close)(FILE *);
+ unsigned char *wend, *wpos;
+ unsigned char *mustbezero_1;
unsigned char *wbase;
- unsigned char *dummy01[3];
+ size_t (*read)(FILE *, unsigned char *, size_t);
+ size_t (*write)(FILE *, const unsigned char *, size_t);
+ off_t (*seek)(FILE *, off_t, int);
unsigned char *buf;
size_t buf_size;
FILE *prev, *next;
@@ -46,26 +51,25 @@ struct __FILE_s {
int pipe_pid;
long dummy2;
short dummy3;
- char dummy4;
+ signed char mode;
signed char lbf;
int lock;
int lockcount;
void *cookie;
off_t off;
int (*flush)(FILE *);
- void **wide_data; /* must be NULL */
- size_t (*read)(FILE *, unsigned char *, size_t);
- size_t (*write)(FILE *, const unsigned char *, size_t);
- off_t (*seek)(FILE *, off_t, int);
- int mode;
- int (*close)(FILE *);
+ void *mustbezero_2;
};
size_t __stdio_read(FILE *, unsigned char *, size_t);
size_t __stdio_write(FILE *, const unsigned char *, size_t);
+size_t __stdout_write(FILE *, const unsigned char *, size_t);
off_t __stdio_seek(FILE *, off_t, int);
int __stdio_close(FILE *);
+int __toread(FILE *);
+int __towrite(FILE *);
+
int __overflow(FILE *, int);
int __oflow(FILE *);
int __uflow(FILE *);
@@ -87,6 +91,12 @@ FILE *__fdopen(int, const char *);
#define feof(f) ((f)->flags & F_EOF)
#define ferror(f) ((f)->flags & F_ERR)
+#define getc_unlocked(f) \
+ ( ((f)->rpos < (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
+
+#define putc_unlocked(c, f) ( ((c)!=(f)->lbf && (f)->wpos<(f)->wend) \
+ ? *(f)->wpos++ = (c) : __overflow((f),(c)) )
+
/* Caller-allocated FILE * operations */
FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
int __fclose_ca(FILE *);