Module Name: src
Committed By: roy
Date: Wed Nov 9 07:40:28 UTC 2011
Modified Files:
src/usr.bin/tic: tic.c
Log Message:
Replace fgetln(3) with the more standard getline(3)
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/tic/tic.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/tic/tic.c
diff -u src/usr.bin/tic/tic.c:1.11 src/usr.bin/tic/tic.c:1.12
--- src/usr.bin/tic/tic.c:1.11 Thu Nov 3 10:12:57 2011
+++ src/usr.bin/tic/tic.c Wed Nov 9 07:40:27 2011
@@ -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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
} 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 @@ main(int argc, char **argv)
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);