From nobody Fri Apr 19 21:52:45 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 4VLpKV1DR3z5HprY; Fri, 19 Apr 2024 21:52:46 +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 4VLpKT6Clpz495J; Fri, 19 Apr 2024 21:52:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713563565; 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=1Lq4NnQH1hKOh3pyyMIhI+gmmBM4Z3WmzZMvw9iRrX8=; b=b4Dd0YtWEMDjp0gWxAk6jtzaOe4DcqzpoTccaSWRW+FB2mQQ+8EAmIlj+vSuuQ3oW4/yeV 0RAQaGBfmp5rf3pY56newIlvQw/UZ7kq3T/5Zk2VZyF3vftQOb8C9wk5wZVCMn9f6OLi9z CtKKSqoCpw3QOwL7iKdb4yIXrlPIcQZqDTmhWYAvKQDiW4Xn2+yc3bTbzjjQMuYuahD3jo lO9FbUugoKCofXhHlLIBKr9PJQAnMaQGyKOKMP2GCjwIfeKN54uzV06c2EE5URALuD11Kj yXBeilLdZUWAuH5A9sT3SPNaTlWJoeFUkW8RHZ/EvnilEk0ZApyN141PqXxdJQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713563565; a=rsa-sha256; cv=none; b=Qwph9UR0lgG16le8u7nadryF+xr7DygNGAsFJuOpBKFN92uE1cZMCw+k56l031S0FG1DTs v6iOWHa/CCkYDKiR4oh7+I5JMDnEvgIGBhLsUIc4JCGYw+g36k6SIs1Z2VCI/MQ7DScpx7 nr6+Aun8SOKuzXrk5vayciAbAzFIfH5lRQAGqsOYAogvlfpIc3FnZ+FAsWV7yp6Vbnrk42 ZK1jDXS0UV+XuLhERexoDRmZqf7qhucVVjBXeVrvTw7cbNs+25Uy9ofWFOkpgw9rviNwjg 0eEppMzwFldsZkjslwsO/JQH59sJNhPuNKl+0Xidb62fvhQdl8/lV6zzOdqLFw== 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=1713563565; 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=1Lq4NnQH1hKOh3pyyMIhI+gmmBM4Z3WmzZMvw9iRrX8=; b=Kdy02l6KNAzcPN9VcaBDk5twgg08+5ltoe7lJrC5PpXIU9y99D8OCA8bkmjXQUShNPELl9 NpRjCr9gQP9M63wnfZu+KRH4caDXF+Yf5XenohD+cLrV/m9d6/EEdLrgfT9u58OlA7axsa E+CzOFDPmRxbBJzPHIo8Nn1ITReq//Ec+h4RM87rkpOm35DUZycKECThiKM2y+eQKJaDSq HCCCaaj91fjIFOQ8HNAWOOCkIamigiIL9qrOFwnuW7ZeuAqo7Ih/XxsxBuEHOLKNa3chEU kbRYuCoYR9WwcgDSlGsWyl2/TJCRYtZ0V/DtKvonx+deD62JJCW9t9ZroSbRSQ== 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 4VLpKT5rCqz18ff; Fri, 19 Apr 2024 21:52:45 +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 43JLqjN6023979; Fri, 19 Apr 2024 21:52:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43JLqjAO023976; Fri, 19 Apr 2024 21:52:45 GMT (envelope-from git) Date: Fri, 19 Apr 2024 21:52:45 GMT Message-Id: <202404192152.43JLqjAO023976@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: 5fbdcd65fe5c - main - xargs: 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: 5fbdcd65fe5cc08959a6ea692b501ec0e98f8b9d Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=5fbdcd65fe5cc08959a6ea692b501ec0e98f8b9d commit 5fbdcd65fe5cc08959a6ea692b501ec0e98f8b9d Author: Martin Tournoij AuthorDate: 2024-04-19 21:11:31 +0000 Commit: Warner Losh CommitDate: 2024-04-19 21:52:22 +0000 xargs: 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/xargs/xargs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index d2c7d087645f..237beff26504 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -770,22 +770,22 @@ static int prompt(void) { regex_t cre; - size_t rsize; + size_t rsize = 0; int match; - char *response; + char *response = NULL; FILE *ttyfp; if ((ttyfp = fopen(_PATH_TTY, "r")) == NULL) return (2); /* Indicate that the TTY failed to open. */ (void)fprintf(stderr, "?..."); (void)fflush(stderr); - if ((response = fgetln(ttyfp, &rsize)) == NULL || + if (getline(&response, &rsize, ttyfp) < 0 || regcomp(&cre, nl_langinfo(YESEXPR), REG_EXTENDED) != 0) { (void)fclose(ttyfp); return (0); } - response[rsize - 1] = '\0'; match = regexec(&cre, response, 0, NULL, 0); + free(response); (void)fclose(ttyfp); regfree(&cre); return (match == 0);