Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Dec 2019 11:03:32 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r355854 - head/usr.bin/diff3
Message-ID:  <201912171103.xBHB3WAa075267@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Tue Dec 17 11:03:32 2019
New Revision: 355854
URL: https://svnweb.freebsd.org/changeset/base/355854

Log:
  Replace homemade getline(3) by actual getline(3)

Modified:
  head/usr.bin/diff3/diff3.c

Modified: head/usr.bin/diff3/diff3.c
==============================================================================
--- head/usr.bin/diff3/diff3.c	Tue Dec 17 10:57:31 2019	(r355853)
+++ head/usr.bin/diff3/diff3.c	Tue Dec 17 11:03:32 2019	(r355854)
@@ -257,28 +257,16 @@ getchange(FILE *b)
 static char *
 get_line(FILE *b, size_t *n)
 {
-	char *cp;
-	size_t len;
-	static char *buf;
-	static size_t bufsize;
+	ssize_t len;
+	static char *buf = NULL;
+	static size_t bufsize = 0;
 
-	if ((cp = fgetln(b, &len)) == NULL)
+	if ((len = getline(&buf, &bufsize, b)) < 0)
 		return (NULL);
 
-	if (cp[len - 1] != '\n')
-		len++;
-	if (len + 1 > bufsize) {
-		do {
-			bufsize += 1024;
-		} while (len + 1 > bufsize);
-		if ((buf = realloc(buf, bufsize)) == NULL)
-			err(EXIT_FAILURE, NULL);
-	}
-	memcpy(buf, cp, len - 1);
-	buf[len - 1] = '\n';
-	buf[len] = '\0';
 	if (n != NULL)
 		*n = len;
+
 	return (buf);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912171103.xBHB3WAa075267>