diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2017-05-16 21:54:51 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2017-05-16 21:54:51 +0000 |
commit | 5183ddf2ed56519b669320095ed00528a71a9393 (patch) | |
tree | d488776e26a534db8a0cf336c81229ce672f22c4 /bin/sh/output.c | |
parent | 7a377fbeb1b2e2fcfb726d2c9fca568dbbc9c2be (diff) | |
download | src-5183ddf2ed56519b669320095ed00528a71a9393.tar.gz src-5183ddf2ed56519b669320095ed00528a71a9393.zip |
sh: Simplify output buffering.
Similarly to how STPUTC was changed, change struct output to store the
pointer just past the end of the available space instead of the size of the
available space, so after writing a character it is only necessary to
increment a pointer and not to decrement a counter.
Notes
Notes:
svn path=/head/; revision=318385
Diffstat (limited to 'bin/sh/output.c')
-rw-r--r-- | bin/sh/output.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/bin/sh/output.c b/bin/sh/output.c index 2f9fc925d88c..64d311f0c2d6 100644 --- a/bin/sh/output.c +++ b/bin/sh/output.c @@ -71,9 +71,9 @@ __FBSDID("$FreeBSD$"); static int doformat_wr(void *, const char *, int); -struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0}; -struct output errout = {NULL, 0, NULL, 256, 2, 0}; -struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0}; +struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0}; +struct output errout = {NULL, NULL, NULL, 256, 2, 0}; +struct output memout = {NULL, NULL, NULL, 0, MEM_OUT, 0}; struct output *out1 = &output; struct output *out2 = &errout; @@ -214,20 +214,19 @@ emptyoutbuf(struct output *dest) INTOFF; dest->buf = ckmalloc(dest->bufsize); dest->nextc = dest->buf; - dest->nleft = dest->bufsize; + dest->bufend = dest->buf + dest->bufsize; INTON; } else if (dest->fd == MEM_OUT) { - offset = dest->bufsize; + offset = dest->nextc - dest->buf; INTOFF; dest->bufsize <<= 1; dest->buf = ckrealloc(dest->buf, dest->bufsize); - dest->nleft = dest->bufsize - offset; + dest->bufend = dest->buf + dest->bufsize; dest->nextc = dest->buf + offset; INTON; } else { flushout(dest); } - dest->nleft--; } @@ -248,7 +247,6 @@ flushout(struct output *dest) if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0) dest->flags |= OUTPUT_ERR; dest->nextc = dest->buf; - dest->nleft = dest->bufsize; } @@ -258,8 +256,9 @@ freestdout(void) INTOFF; if (output.buf) { ckfree(output.buf); + output.nextc = NULL; output.buf = NULL; - output.nleft = 0; + output.bufend = NULL; } INTON; } |