From d5b2601b8fbd384bded9f0a76f320f940cf31a9a Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 21 Feb 1989 10:01:55 +0000 Subject: [PATCH] use a larger buffer on larger machines --- include/_tail_cc/stdio.h | 11 +++++++++++ lang/cem/libcc/stdio/data.c | 9 +++------ lang/cem/libcc/stdio/fflush.c | 4 ++-- lang/cem/libcc/stdio/fillbuf.c | 18 +++++++++++++----- lang/cem/libcc/stdio/flushbuf.c | 21 +++++++-------------- lang/cem/libcc/stdio/freopen.c | 3 +-- lang/cem/libcc/stdio/setbuf.c | 10 ++++++---- 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/include/_tail_cc/stdio.h b/include/_tail_cc/stdio.h index d215b3970..e40c92206 100644 --- a/include/_tail_cc/stdio.h +++ b/include/_tail_cc/stdio.h @@ -4,6 +4,16 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ #define BUFSIZ 1024 +#ifdef vax +#define _NBF 8 +#endif +#ifdef mc68020 +#define _NBF 8 +#endif +#ifndef _NBF +#define _NBF 1 +#endif +#define _BUFSIZ (_NBF * BUFSIZ) #define _NFILES 20 #define NULL 0 #define EOF (-1) @@ -24,6 +34,7 @@ extern struct _io_buf { int _flags; unsigned char *_buf; unsigned char *_ptr; + int _bufsiz; } *_io_table[_NFILES], _stdin, _stdout, _stderr; diff --git a/lang/cem/libcc/stdio/data.c b/lang/cem/libcc/stdio/data.c index 1e182284f..bfaafd2b7 100644 --- a/lang/cem/libcc/stdio/data.c +++ b/lang/cem/libcc/stdio/data.c @@ -1,19 +1,16 @@ /* $Header$ */ #include -unsigned char _sobuf[BUFSIZ]; -unsigned char _sibuf[BUFSIZ]; - struct _io_buf _stdin = { - 0, 0, IO_READMODE , _sibuf, _sibuf + 0, 0, IO_READMODE , 0, 0, 0 }; struct _io_buf _stdout = { - 1, 0, IO_WRITEMODE, 0, 0 + 1, 0, IO_WRITEMODE, 0, 0, 0 }; struct _io_buf _stderr = { - 2, 0, IO_WRITEMODE + IO_UNBUFF, NULL, NULL + 2, 0, IO_WRITEMODE + IO_UNBUFF, 0, 0, 0 }; struct _io_buf *_io_table[_NFILES] = { diff --git a/lang/cem/libcc/stdio/fflush.c b/lang/cem/libcc/stdio/fflush.c index d2438d95a..7781bd1ce 100644 --- a/lang/cem/libcc/stdio/fflush.c +++ b/lang/cem/libcc/stdio/fflush.c @@ -12,14 +12,14 @@ FILE *iop; !io_testflag(iop,IO_WRITEMODE) ) return(0); - count = BUFSIZ - iop->_count; + count = iop->_bufsiz - iop->_count; if ( count <= 0 ) return(0); c1 = write(iop->_fd,iop->_buf,count); if ( count == c1 ) { - iop->_count = BUFSIZ; + iop->_count = iop->_bufsiz; iop->_ptr = iop->_buf; return(count); } diff --git a/lang/cem/libcc/stdio/fillbuf.c b/lang/cem/libcc/stdio/fillbuf.c index 37d4a2e72..856071f65 100644 --- a/lang/cem/libcc/stdio/fillbuf.c +++ b/lang/cem/libcc/stdio/fillbuf.c @@ -17,13 +17,21 @@ register FILE *iop; return (EOF); if (! io_testflag(iop, IO_UNBUFF) && ! iop->_buf) { - iop->_buf = (unsigned char *) malloc(BUFSIZ); - if (! iop->_buf) iop->_flags |= IO_UNBUFF; - else iop->_flags |= IO_MYBUF; + iop->_buf = (unsigned char *) malloc(_BUFSIZ); + if (! iop->_buf) { + iop->_flags |= IO_UNBUFF; + } + else { + iop->_flags |= IO_MYBUF; + iop->_bufsiz = _BUFSIZ; + } + } + if (! iop->_buf) { + iop->_buf = &ch[fileno(iop)]; + iop->_bufsiz = 1; } - if (! iop->_buf) iop->_buf = &ch[fileno(iop)]; iop->_ptr = iop->_buf; - iop->_count = read(iop->_fd, iop->_buf, io_testflag(iop, IO_UNBUFF)? 1 : BUFSIZ); + iop->_count = read(iop->_fd, iop->_buf, iop->_bufsiz); if (iop->_count <= 0){ if (iop->_count == 0) { diff --git a/lang/cem/libcc/stdio/flushbuf.c b/lang/cem/libcc/stdio/flushbuf.c index a460a37a0..f023a1599 100644 --- a/lang/cem/libcc/stdio/flushbuf.c +++ b/lang/cem/libcc/stdio/flushbuf.c @@ -8,26 +8,19 @@ _flushbuf(c, iop) if (fileno(iop) < 0) return EOF; if (! io_testflag(iop, IO_UNBUFF)) { if (iop->_buf == 0) { - if (iop == stdout) { - if (isatty(fileno(stdout))) { - iop->_flags |= IO_UNBUFF; - } - else { - extern unsigned char _sobuf[]; - - iop->_buf = _sobuf; - iop->_count = BUFSIZ-1; - } + if (iop == stdout && isatty(fileno(stdout))) { + iop->_flags |= IO_UNBUFF; } else { extern char *malloc(); - - if (!(iop->_buf = (unsigned char *) malloc(BUFSIZ))) { + + if (!(iop->_buf = (unsigned char *) malloc(_BUFSIZ))) { iop->_flags |= IO_UNBUFF; } else { iop->_flags |= IO_MYBUF; - iop->_count = BUFSIZ-1; + iop->_bufsiz = _BUFSIZ; + iop->_count = _BUFSIZ-1; } } iop->_ptr = iop->_buf; @@ -47,7 +40,7 @@ _flushbuf(c, iop) else { int count = iop->_ptr - iop->_buf; - iop->_count = BUFSIZ - 1; + iop->_count = iop->_bufsiz - 1; iop->_ptr = iop->_buf + 1; if (count > 0) { diff --git a/lang/cem/libcc/stdio/freopen.c b/lang/cem/libcc/stdio/freopen.c index 1dcde67f7..f77d8f29e 100644 --- a/lang/cem/libcc/stdio/freopen.c +++ b/lang/cem/libcc/stdio/freopen.c @@ -8,7 +8,6 @@ FILE *freopen(name,mode,fp) char *name , *mode; register FILE *fp; { - char *malloc(); int fd, flags = fp->_flags & ~(IO_WRITEMODE|IO_READMODE|IO_ERR|IO_EOF|IO_PERPRINTF); @@ -52,7 +51,7 @@ register FILE *fp; } fp->_count = 0; if (fp->_buf && !(flags & IO_UNBUFF) && (flags & IO_WRITEMODE)) - fp->_count = BUFSIZ; + fp->_count = fp->_bufsiz; fp->_fd = fd; fp->_flags = flags; return(fp); diff --git a/lang/cem/libcc/stdio/setbuf.c b/lang/cem/libcc/stdio/setbuf.c index 64ff3ef08..215d67109 100644 --- a/lang/cem/libcc/stdio/setbuf.c +++ b/lang/cem/libcc/stdio/setbuf.c @@ -13,10 +13,12 @@ char *buffer; iop->_buf = (unsigned char *) buffer; iop->_count = 0; - if ( iop->_buf == NULL ) + if ( iop->_buf == NULL ) { iop->_flags |= IO_UNBUFF; - else - iop->_count = BUFSIZ; - + iop->_bufsiz = 1; + } else { + if (io_testflag(iop, IO_WRITEMODE)) iop->_count = BUFSIZ; + iop->_bufsiz = BUFSIZ; + } iop->_ptr = iop->_buf; } -- 2.34.1