From nobody Wed Oct 12 08:42:46 2022 X-Original-To: dev-commits-src-all@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 4MnR47094vz4fm9K; Wed, 12 Oct 2022 08:42:47 +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 4MnR466n3Cz3WTP; Wed, 12 Oct 2022 08:42:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665564167; 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=dN/YmWCQgTOk3m64VM4gZA9Q5suN0nAKmXgFAzGatPw=; b=BsqCCWOfAj8f2Xn39yo+dvwIh2a2lQ4SLpHlPa+rTANlWu5TArcHO84L4MxCy99CvOWmci G1J8JPG8IIWna1l1asDLoBlBUTu4peR7+cgJdXeGMAq7uUs3Ix/uW2WQG5AfiICzmPGxfs 2zH8pitoH6jvwF9EoCjFFe+I8h0tEL6Ib2eBg8Kd+JWsRL+i3e37eZg+mzkFZMo7c18qYS Gdbg4mS/AUXLtlN3Ac+HUMRJtw1OjD2o8exF+IBKBfKMelYucdh1XY+Nicsp6LPjW3kVFz K6OMEOSxjKZNg4rSifVr+XpfcKdZBF7myf8s0JHGwQJtgbKySgwQIzKQwC9dvw== 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 4MnR465qcbz1G3X; Wed, 12 Oct 2022 08:42:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29C8gkLh005866; Wed, 12 Oct 2022 08:42:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29C8gkxB005865; Wed, 12 Oct 2022 08:42:46 GMT (envelope-from git) Date: Wed, 12 Oct 2022 08:42:46 GMT Message-Id: <202210120842.29C8gkxB005865@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: f9bf4beab044 - stable/12 - ident: replace sbuf(9) with open_memstream(3) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: f9bf4beab044d34adf6c92bdca40952d5c26ad96 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665564166; 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=dN/YmWCQgTOk3m64VM4gZA9Q5suN0nAKmXgFAzGatPw=; b=gFxEKrEOTsGPjVXxMbgZfrHDsIjS6eS1WoOB/oLeeTItpJxIf/StER3tQvWZ3Q1LaqCKHZ rxoIpZrNapfvZzqeU9wn5J2pLT4sYed7/udwtd+KmXYCaTN7s25+jhd9nyIOU82+tSBXks n8zJioJBr3W1Pg3qYZ6tlTXtU7RkwAO3i+0EFt5cN0xwEP5pcEvUBkdNyCr+2VSBWY9Lv4 s3fbsI5j/cSNxVT7Hc6yhyUfMsEQaN9ejNbZsQuHuRR3JnjymSZmePIHK9xsBPk+O3qP7A WgywyFaEL7WFpVGxerS5lbPgLttvKgZnvGdkVG51kVLBTXgglbN9Vasi17tyxQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665564167; a=rsa-sha256; cv=none; b=Aj99eTVld5siTwccnPUKVJxJ35uU+fhhAoUNOVYKF4x3ckJDLHKRdhqt92hpO6geC1qfMr PentYZuRmI+3KR/Af5G+t5Iw2Og4LzCHNmjVPNCB7+LxPdw21HHdERH8N/0QMmqkJaaN53 EYQ7HBmWLhtX2KRUGSz3+ZrB6D0R0NovCnaVBUswiostL9BtviPjANbipyEOOu7sG0dqOM uA9tsCFtipxvlTr7EhQ/ywLZbaSFGmgA3Qbl5luUhQtA7sNPoiZ6XM/4L7jrjkprD39qHY qoXj3rQ7zpfUTgE/l92rbbxdlyAkQYbOaV5OaAJOtb1ohGt+N9K7qQguV2BJLw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=f9bf4beab044d34adf6c92bdca40952d5c26ad96 commit f9bf4beab044d34adf6c92bdca40952d5c26ad96 Author: Baptiste Daroussin AuthorDate: 2021-10-28 13:39:24 +0000 Commit: Baptiste Daroussin CommitDate: 2022-10-12 08:42:22 +0000 ident: replace sbuf(9) with open_memstream(3) This change makes ident only dependant on libc functions This makes our ident(1) more portable, also the fact that we only depend on libc which is maintained with excellent backward compatibility means that if one day ident is removed from base, someone using FreeBSD 22 will be able to fetch ident from FreeBSD 14 to run ident against FreeBSD 1.0 binary MFC After: 1 week (cherry picked from commit 1a4d5f13ba19308f9909ef712c5d7eebaf1f9806) --- usr.bin/ident/Makefile | 2 -- usr.bin/ident/ident.c | 35 +++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/usr.bin/ident/Makefile b/usr.bin/ident/Makefile index e0a3a80f7b09..0e0734081607 100644 --- a/usr.bin/ident/Makefile +++ b/usr.bin/ident/Makefile @@ -4,8 +4,6 @@ PROG= ident -LIBADD= sbuf - HAS_TESTS= SUBDIR.${MK_TESTS}+= tests diff --git a/usr.bin/ident/ident.c b/usr.bin/ident/ident.c index aa9612d2fce1..14ff8ec8f335 100644 --- a/usr.bin/ident/ident.c +++ b/usr.bin/ident/ident.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2015 Baptiste Daroussin + * Copyright (c) 2015-2021 Baptiste Daroussin * Copyright (c) 2015 Xin LI * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -58,10 +59,17 @@ scan(FILE *fp, const char *name, bool quiet) bool hasid = false; bool subversion = false; analyzer_states state = INIT; - struct sbuf *id = sbuf_new_auto(); + FILE* buffp; + char *buf; + size_t sz; locale_t l; l = newlocale(LC_ALL_MASK, "C", NULL); + sz = 0; + buf = NULL; + buffp = open_memstream(&buf, &sz); + if (buffp == NULL) + err(EXIT_FAILURE, "open_memstream()"); if (name != NULL) printf("%s:\n", name); @@ -80,9 +88,11 @@ scan(FILE *fp, const char *name, bool quiet) case DELIM_SEEN: if (isalpha_l(c, l)) { /* Transit to KEYWORD if we see letter */ - sbuf_clear(id); - sbuf_putc(id, '$'); - sbuf_putc(id, c); + if (buf != NULL) + memset(buf, 0, sz); + rewind(buffp); + fputc('$', buffp); + fputc(c, buffp); state = KEYWORD; continue; @@ -95,7 +105,7 @@ scan(FILE *fp, const char *name, bool quiet) } break; case KEYWORD: - sbuf_putc(id, c); + fputc(c, buffp); if (isalpha_l(c, l)) { /* @@ -125,7 +135,7 @@ scan(FILE *fp, const char *name, bool quiet) break; case PUNC_SEEN: case PUNC_SEEN_SVN: - sbuf_putc(id, c); + fputc(c, buffp); switch (c) { case ':': @@ -159,13 +169,13 @@ scan(FILE *fp, const char *name, bool quiet) } break; case TEXT: - sbuf_putc(id, c); + fputc(c, buffp); if (iscntrl_l(c, l)) { /* Control characters are not allowed in this state */ state = INIT; } else if (c == '$') { - sbuf_finish(id); + fflush(buffp); /* * valid ident should end with a space. * @@ -175,9 +185,9 @@ scan(FILE *fp, const char *name, bool quiet) * subversion mode. No length check is enforced * because GNU RCS ident(1) does not do it either. */ - c = sbuf_data(id)[sbuf_len(id) - 2]; + c = buf[strlen(buf) -2 ]; if (c == ' ' || (subversion && c == '#')) { - printf(" %s\n", sbuf_data(id)); + printf(" %s\n", buf); hasid = true; } state = INIT; @@ -186,7 +196,8 @@ scan(FILE *fp, const char *name, bool quiet) break; } } - sbuf_delete(id); + fclose(buffp); + free(buf); freelocale(l); if (!hasid) {