Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/tic Replace fgetln(3) with the more standard getline(3)



details:   https://anonhg.NetBSD.org/src/rev/802f6019d168
branches:  trunk
changeset: 771100:802f6019d168
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Nov 09 07:40:27 2011 +0000

description:
Replace fgetln(3) with the more standard getline(3)

diffstat:

 usr.bin/tic/tic.c |  20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diffs (59 lines):

diff -r 7b67118b36e6 -r 802f6019d168 usr.bin/tic/tic.c
--- a/usr.bin/tic/tic.c Wed Nov 09 05:47:54 2011 +0000
+++ b/usr.bin/tic/tic.c Wed Nov 09 07:40:27 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tic.c,v 1.11 2011/11/03 10:12:57 roy Exp $ */
+/* $NetBSD: tic.c,v 1.12 2011/11/09 07:40:27 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: tic.c,v 1.11 2011/11/03 10:12:57 roy Exp $");
+__RCSID("$NetBSD: tic.c,v 1.12 2011/11/09 07:40:27 roy Exp $");
 
 #include <sys/types.h>
 
@@ -443,7 +443,8 @@
        char *source, *p, *buf, *ofile;
        FILE *f;
        DBM *db;
-       size_t len, buflen, nterm, nalias;
+       size_t buflen, nterm, nalias;
+       ssize_t len;
        TBUF tbuf;
        TERM *term;
 
@@ -506,12 +507,13 @@
        } else
                db = NULL; /* satisfy gcc warning */
 
-       tbuf.buflen = tbuf.bufpos = 0;  
-       while ((buf = fgetln(f, &buflen)) != NULL) {
+       buf = NULL;
+       buflen = tbuf.buflen = tbuf.bufpos = 0; 
+       while ((len = getline(&buf, &buflen, f)) != -1) {
                /* Skip comments */
                if (*buf == '#')
                        continue;
-               if (buf[buflen - 1] != '\n') {
+               if (buf[len - 1] != '\n') {
                        process_entry(&tbuf, flags);
                        dowarn("last line is not a comment"
                            " and does not end with a newline");
@@ -525,10 +527,10 @@
                        process_entry(&tbuf, flags);
                
                /* Grow the buffer if needed */
-               grow_tbuf(&tbuf, buflen);
+               grow_tbuf(&tbuf, len);
                /* Append the string */
-               memcpy(tbuf.buf + tbuf.bufpos, buf, buflen);
-               tbuf.bufpos += buflen;
+               memcpy(tbuf.buf + tbuf.bufpos, buf, len);
+               tbuf.bufpos += len;
        }
        /* Process the last entry if not done already */
        process_entry(&tbuf, flags);



Home | Main Index | Thread Index | Old Index