From nobody Fri Apr 19 21:52:41 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VLpKP3hq9z5HprS; Fri, 19 Apr 2024 21:52:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VLpKP2tT4z49ML; Fri, 19 Apr 2024 21:52:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713563561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z+7KUXkSVAhFh9hfp6U7SN0y65+w5iUXKlK82p3n8LM=; b=Y+mIda4rTlhrKjyit7q+Otr9SP9xWVn3D4QXkHb9bHAeNKCHiX1iFBAyGKZwz1CzjBNgXZ Kv5fxBJl7PkLmyWHq3Vf3sOCniLgNa4qC5krzUrH4VlWfOJds2zRZx2dhB3AsBdhH7KSBn m3SQZSCccC+GLbG1TrqTXVZPMgwY0uvZ4rF9XKDxwLJlGBBYu/rQsUUxEXzLcCha4reO/9 IQ6rcD6hTfOAZIvIWOYHJE7EJl/snfnS4/XHhCFzlu72VtZBMc9zAl8K8cxF6g1MsgsqhS IQdrtj0KbcRiCjMeNKWLkg0mNxjLNf9av1dMOHqsdVLWWMrKMcvLkWF1STAQcA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713563561; a=rsa-sha256; cv=none; b=t7fdysH+1vK3/GiAdkKTDLAG3t+aPvyjV66wxHpf4az8+Ybia5WEhMXPviMxdMdrhDLyGv i5vQf/SxqHIIj6sInkepX+kCEZXt9Mmtd0Ataz0IBaNpyeBWAEiqCwCibTRl3Jv2f8PI1b ibW+9KYbCpzoLjY+nf+NEE0hzPOcmggLgZM81Oua0GULqBVdXTr8oh9pGc9WfzDhwqNXPe sz1U0edxM6xd6fHKryDd1MZwxFE9aodeezfFEIS4uUKAsfbLbgf90x4Nn/hk4RRgJJLiWv gNkYhE4Dg2OCbfRv0Ryjw0XQRTBLBophjOqaV7pQhvIxP0Sh5K0Eq7QN7aLkuA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713563561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z+7KUXkSVAhFh9hfp6U7SN0y65+w5iUXKlK82p3n8LM=; b=JcxI4Nf4QtqDkGv8il9A8a5HxlqBnlsf48ULxN9+wl89B5AqmvSEorhSxU0McoqgDDyiZG Ea42j90cX7/Qs29dePA3nPHXq+L49GlJqPiBK7JNfOJnOBUrf+N9PuNVDabFBVxRO3bVzx iBi+tlcmHM8qXbvX6I9xK1g8MA29YD/ifV0TW1Tuw2mK6mG75yPIpUzLuBydQg07htQb3i HBEEWiUxz8VacuMJ1qUn3Y7eu03e84S6Nl9fs/GE16F73RoSJ6QtqBiV5fcLJqFEo1Q8kw RijenEc9kkoHQOZsIbnEKlhje2xKDqqXoL0IrME6LK/tpsBb7jibXNG6BIM18Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VLpKP2Tx6z18tp; Fri, 19 Apr 2024 21:52:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43JLqfHk023792; Fri, 19 Apr 2024 21:52:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43JLqfel023789; Fri, 19 Apr 2024 21:52:41 GMT (envelope-from git) Date: Fri, 19 Apr 2024 21:52:41 GMT Message-Id: <202404192152.43JLqfel023789@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 9744821765fc - main - diff: use getline() instead of fgetln() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9744821765fccd6c9b44d47804b6913cdf616d4e Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=9744821765fccd6c9b44d47804b6913cdf616d4e commit 9744821765fccd6c9b44d47804b6913cdf616d4e Author: Martin Tournoij AuthorDate: 2024-04-19 21:11:30 +0000 Commit: Warner Losh CommitDate: 2024-04-19 21:52:21 +0000 diff: use getline() instead of fgetln() This replaces fgetln() with getline(). The main reason for this is portability, making things easier for people who want to compile these tools on non-FreeBSD systems. I appreciate that's probably not the top concern for FreeBSD base tools, but fgetln() is impossible to port to most platforms, as concurrent access is essentially impossible to implement fully correct without the line buffer on the FILE struct. Other than this, many generic FreeBSD tools compile fairly cleanly on Linux with a few small changes. Most uses of fgetln() pre-date getline() support (added in 2009 with 69099ba2ec8b), and there's been some previous patches (ee3ca711a898 8c98e6b1a7f3 1a2a4fc8ce1b) for other tools. Obtained from: https://github.com/dcantrell/bsdutils and https://github.com/chimera-linux/chimerautils Signed-off-by: Martin Tournoij Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/893 --- usr.bin/diff/diff.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 15ebbca28bd7..67aab0de91b5 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -517,20 +517,23 @@ static void read_excludes_file(char *file) { FILE *fp; - char *buf, *pattern; - size_t len; + char *pattern = NULL; + size_t blen = 0; + ssize_t len; if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) err(2, "%s", file); - while ((buf = fgetln(fp, &len)) != NULL) { - if (buf[len - 1] == '\n') - len--; - if ((pattern = strndup(buf, len)) == NULL) - err(2, "xstrndup"); + while ((len = getline(&pattern, &blen, fp)) >= 0) { + if ((len > 0) && (pattern[len - 1] == '\n')) + pattern[len - 1] = '\0'; push_excludes(pattern); + /* we allocate a new string per line */ + pattern = NULL; + blen = 0; } + free(pattern); if (strcmp(file, "-") != 0) fclose(fp); }