From de9a3738c9c7dbd2b92691d29dbe91d1777fe031 Mon Sep 17 00:00:00 2001 From: "Kurt A. Schoens" Date: Fri, 21 Nov 1980 17:10:46 -0800 Subject: [PATCH] Made fast version of readline for setptr; use fputs not putline there also for speed SCCS-vsn: usr.bin/mail/fio.c 1.6 --- usr/src/usr.bin/mail/fio.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/usr/src/usr.bin/mail/fio.c b/usr/src/usr.bin/mail/fio.c index faca996ee4..29df639090 100644 --- a/usr/src/usr.bin/mail/fio.c +++ b/usr/src/usr.bin/mail/fio.c @@ -10,7 +10,7 @@ * File I/O. */ -static char *SccsId = "@(#)fio.c 1.5 %G%"; +static char *SccsId = "@(#)fio.c 1.6 %G%"; /* * Set up the input pointers while copying the mail file into @@ -38,7 +38,7 @@ setptr(ibuf) maybe = 1; flag = MUSED|MNEW; for (;;) { - if ((count = readline(ibuf, linebuf)) == 0) { + if ((count = freadline(ibuf, linebuf)) == 0) { this.m_flag = flag; flag = MUSED|MNEW; this.m_offset = offsetof(offset); @@ -54,7 +54,7 @@ setptr(ibuf) close(mestmp); return; } - if (putline(otf, linebuf) < 0) { + if (fputs(linebuf, otf) == NULL || putc('\n', otf) == EOF) { perror("/tmp"); exit(1); } @@ -120,6 +120,38 @@ putline(obuf, linebuf) return(c+1); } +/* + * Quickly read a line from the specified input into the line + * buffer; return characters read. + */ + +freadline(ibuf, linebuf) + register FILE *ibuf; + register char *linebuf; +{ + register int c; + register char *cp; + + c = getc(ibuf); + cp = linebuf; + while (c != '\n' && c != EOF) { + if (c == 0) { + c = getc(ibuf); + continue; + } + if (cp - linebuf >= BUFSIZ-1) { + *cp = 0; + return(cp - linebuf + 1); + } + *cp++ = c; + c = getc(ibuf); + } + if (c == EOF && cp == linebuf) + return(0); + *cp = 0; + return(cp - linebuf + 1); +} + /* * Read up a line from the specified input into the line * buffer. Return the number of characters read. Do not -- 2.20.1