From nobody Sun Oct 30 04:44:57 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 4N0NxP45lLz4gq3K; Sun, 30 Oct 2022 04:44:57 +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 4N0NxP3ZL9z4Frs; Sun, 30 Oct 2022 04:44:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667105097; 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=Jk1NDDEoT5nrsRfSa7f83RkMbB8iMet57St52qBuy2E=; b=T/fmJV3z6ag8+rJf86cIfQyk2ZtJpg+X44tGp+JJyulwlZTm67L4PuvDuLMCek6Epdh5PP byuJSa8lR8RwK8GXvqRjguESvna21yJ2yUbES7jaB6R9AUAZFDTYqjj1/igt35XJ+tQ6Zo LE9lPr7TeFG7EU8diJc4wr7vSE6aKNjEX2YPKyqXdu7kplq+XBxVee6Goi64hQNIoFmac/ u9zolc8KWlVIy4pjmQvjYcq7A5zhrl5e03l+vw6JYg+O4E54ne+6Brnnkz5d9us204tqvS CTCNt2NeZ9sxhQPjSi1Uu2JRv0t8IBZlWFbPQQdv7f/5k/uxnyilleuPwEbcwg== 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 4N0NxP2MkkzktK; Sun, 30 Oct 2022 04:44:57 +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 29U4ivpp006678; Sun, 30 Oct 2022 04:44:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29U4iv59006677; Sun, 30 Oct 2022 04:44:57 GMT (envelope-from git) Date: Sun, 30 Oct 2022 04:44:57 GMT Message-Id: <202210300444.29U4iv59006677@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Xin LI Subject: git: 97a6bb4a3f47 - stable/12 - MFV: Restore the ability to process files from stdin immediately. 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: delphij X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 97a6bb4a3f4712ec2d9443f79b6a6e8668ef2b38 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667105097; 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=Jk1NDDEoT5nrsRfSa7f83RkMbB8iMet57St52qBuy2E=; b=Oy5NQOXewh/riv8JuVbMOCvKiuK7tKjOIRr52VLnTJxWV5C44zZowbFC4FvLxRYeVrO/oj lK47Csmqgz6hLu5O5jM6W5Y9t9IMY1sfRRblEUTcIen6pSBsWpgZZ6MwnxX6WR+pGIG2hS KS22s9/P+IAtz9xWyz+9F6cp28xBWc8vITSXZVab3QigWtPnKuqXIaTNIflKBGrQbyjlOa A6O09Ckmitl3F3eI2voZUSY1UC9KjXwcSh0AB3tvxI2AwCqCPJLNA9X5hbbrlL98D3Xh9H 556S82cvtSvbYV+GNv7HK/Es9wgg1bf54pWnuNTmPDVwxVJxW4ldULo/1mow/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667105097; a=rsa-sha256; cv=none; b=vQ5fMNe04Khgwr4oERzIF+HDi+QJSiCbyNj7X8bS9tLhTCIMuvPn/9+KS0GrW1t1yUBbyz HDpINYyAK1eAVAQ2AAkkWefHJGhgfTtHPvZWXD74nfOzXXzKfEgVhtCvrldD3IP43mS6OF YQZaKSaIEdnvjtGiQ9/baDgpSQf2yP1DcjX77iXZOdv8Mby5mJbmgPSSPhFQ6locMPZxHz QvUH4XwZXxfoYs8m9C2N19UlI4yqkcKPZg5A4VXt47PMv8xsYWN9xLQGAgXrQ20bU6FLJ+ h7y6aYp0RzVy4BQeqdw/XAX2qkJm0nM0VUL+IhF9RtEGWP4kr2KnDgriX4onUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=97a6bb4a3f4712ec2d9443f79b6a6e8668ef2b38 commit 97a6bb4a3f4712ec2d9443f79b6a6e8668ef2b38 Author: Xin LI AuthorDate: 2022-10-27 07:12:53 +0000 Commit: Xin LI CommitDate: 2022-10-30 04:42:45 +0000 MFV: Restore the ability to process files from stdin immediately. PR: bin/267221 (cherry picked from commit 07dfb236c81483c2f08a3976f6d44ce307f4ceaf) --- contrib/file/doc/file.man | 4 ++-- contrib/file/src/file.c | 36 ++++++++++++++++++++++-------------- contrib/file/src/file_opts.h | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/contrib/file/doc/file.man b/contrib/file/doc/file.man index 5be5e9b093e4..91470b8e199d 100644 --- a/contrib/file/doc/file.man +++ b/contrib/file/doc/file.man @@ -1,5 +1,5 @@ -.\" $File: file.man,v 1.144 2021/02/05 22:08:31 christos Exp $ -.Dd February 5, 2021 +.\" $File: file.man,v 1.146 2022/10/26 16:56:14 christos Exp $ +.Dd October 26, 2022 .Dt FILE __CSECTION__ .Os .Sh NAME diff --git a/contrib/file/src/file.c b/contrib/file/src/file.c index 0efbb92cd520..46b4256a0c24 100644 --- a/contrib/file/src/file.c +++ b/contrib/file/src/file.c @@ -512,11 +512,8 @@ unwrap(struct magic_set *ms, const char *fn) size_t llen = 0; int wid = 0, cwid; int e = 0; - size_t fi = 0, fimax = 100; - char **flist = CAST(char **, malloc(sizeof(*flist) * fimax)); - - if (flist == NULL) -out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); + size_t fi = 0, fimax = 0; + char **flist = NULL; if (strcmp("-", fn) == 0) f = stdin; @@ -530,26 +527,37 @@ out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); while ((len = getline(&line, &llen, f)) > 0) { if (line[len - 1] == '\n') line[len - 1] = '\0'; + cwid = file_mbswidth(ms, line); + if (nobuffer) { + e |= process(ms, line, cwid); + free(line); + line = NULL; + llen = 0; + continue; + } + if (cwid > wid) + wid = cwid; if (fi >= fimax) { fimax += 100; char **nf = CAST(char **, realloc(flist, fimax * sizeof(*flist))); - if (nf == NULL) - goto out; + if (nf == NULL) { + file_err(EXIT_FAILURE, + "Cannot allocate memory for file list"); + } flist = nf; } flist[fi++] = line; - cwid = file_mbswidth(ms, line); - if (cwid > wid) - wid = cwid; line = NULL; llen = 0; } - fimax = fi; - for (fi = 0; fi < fimax; fi++) { - e |= process(ms, flist[fi], wid); - free(flist[fi]); + if (!nobuffer) { + fimax = fi; + for (fi = 0; fi < fimax; fi++) { + e |= process(ms, flist[fi], wid); + free(flist[fi]); + } } free(flist); diff --git a/contrib/file/src/file_opts.h b/contrib/file/src/file_opts.h index 978c8b64434c..c78a8df2a800 100644 --- a/contrib/file/src/file_opts.h +++ b/contrib/file/src/file_opts.h @@ -37,7 +37,7 @@ OPT('e', "exclude", 1, 0, " performed for file. Valid tests are:\n" " %e\n") OPT_LONGONLY("exclude-quiet", 1, 0, - " TEST like exclude, but ignore unknown tests\n", OPT_EXCLUDE_QUIET) + " TEST like exclude, but ignore unknown tests\n", OPT_EXCLUDE_QUIET) OPT('f', "files-from", 1, 0, " FILE read the filenames to be examined from FILE\n") OPT('F', "separator", 1, 0,