From 9ea52b92ef6fd605812cc834e4e56a24be55e2b3 Mon Sep 17 00:00:00 2001 From: roy Date: Wed, 9 Nov 2011 07:40:27 +0000 Subject: Replace fgetln(3) with the more standard getline(3) --- usr.bin/tic/tic.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'usr.bin/tic') diff --git a/usr.bin/tic/tic.c b/usr.bin/tic/tic.c index 1ff23d837f2..d710d2a9240 100644 --- a/usr.bin/tic/tic.c +++ b/usr.bin/tic/tic.c @@ -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 -__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 @@ -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); -- cgit