Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/grep Use the more portable getline.
details: https://anonhg.NetBSD.org/src/rev/e4a78b9f6a8a
branches: trunk
changeset: 764380:e4a78b9f6a8a
user: joerg <joerg%NetBSD.org@localhost>
date: Mon Apr 18 03:48:23 2011 +0000
description:
Use the more portable getline.
diffstat:
usr.bin/grep/grep.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diffs (36 lines):
diff -r 97e7ccb5a614 -r e4a78b9f6a8a usr.bin/grep/grep.c
--- a/usr.bin/grep/grep.c Mon Apr 18 03:47:40 2011 +0000
+++ b/usr.bin/grep/grep.c Mon Apr 18 03:48:23 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: grep.c,v 1.5 2011/04/18 03:27:40 joerg Exp $ */
+/* $NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $ */
/* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */
/* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */
@@ -34,7 +34,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: grep.c,v 1.5 2011/04/18 03:27:40 joerg Exp $");
+__RCSID("$NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $");
#include <sys/stat.h>
#include <sys/types.h>
@@ -292,11 +292,15 @@
FILE *f;
char *line;
size_t len;
+ ssize_t rlen;
if ((f = fopen(fn, "r")) == NULL)
err(2, "%s", fn);
- while ((line = fgetln(f, &len)) != NULL)
- add_pattern(line, *line == '\n' ? 0 : len);
+ line = NULL;
+ len = 0;
+ while ((rlen = getline(&line, &len, f)) != -1)
+ add_pattern(line, *line == '\n' ? 0 : (size_t)rlen);
+ free(line);
if (ferror(f))
err(2, "%s", fn);
fclose(f);
Home |
Main Index |
Thread Index |
Old Index