Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/fmt - use BUF_SIZE instead of BUFSIZ



details:   https://anonhg.NetBSD.org/src/rev/1b94de90ec38
branches:  trunk
changeset: 586897:1b94de90ec38
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 04 22:05:26 2006 +0000

description:
- use BUF_SIZE instead of BUFSIZ
- operator precedence in length calculation
- update buffer end pointer when buffer position does not change.

diffstat:

 usr.bin/fmt/buffer.h |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (49 lines):

diff -r c5adecd5a733 -r 1b94de90ec38 usr.bin/fmt/buffer.h
--- a/usr.bin/fmt/buffer.h      Wed Jan 04 22:02:11 2006 +0000
+++ b/usr.bin/fmt/buffer.h      Wed Jan 04 22:05:26 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buffer.h,v 1.2 2005/12/24 20:52:20 perry Exp $ */
+/*     $NetBSD: buffer.h,v 1.3 2006/01/04 22:05:26 christos Exp $      */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <err.h>
 
+#define BUF_SIZE       BUFSIZ
 struct buffer {
        char *ptr;
        char *bptr;
@@ -50,10 +51,10 @@
 static void
 buf_init(struct buffer *buf)
 {
-       buf->ptr = buf->bptr = malloc(BUFSIZ);
+       buf->ptr = buf->bptr = malloc(BUF_SIZE);
        if (buf->ptr == NULL)
                err(1, "Cannot allocate buffer");
-       buf->eptr = buf->ptr + BUFSIZ;
+       buf->eptr = buf->ptr + BUF_SIZE;
 }
 
 static void
@@ -67,14 +68,16 @@
 {
        ptrdiff_t diff;
        size_t len = (buf->eptr - buf->bptr) + 
-           minsize > BUFSIZ ? minsize : BUFSIZ;
+           (minsize > BUF_SIZE ? minsize : BUF_SIZE);
        char *nptr = realloc(buf->bptr, len);
 
        if (nptr == NULL)
                err(1, "Cannot grow buffer");
 
-       if (nptr == buf->bptr)
+       if (nptr == buf->bptr) {
+               buf->eptr = buf->bptr + len;
                return;
+       }
 
        diff = nptr - buf->bptr;
        buf->bptr += diff;



Home | Main Index | Thread Index | Old Index