git: 28f11883e8d4 - releng/12.4 - MFV: Restore the ability to process files from stdin immediately.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 30 Oct 2022 19:43:51 UTC
The branch releng/12.4 has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=28f11883e8d4007f27f6d39f4a95a703bc572da4 commit 28f11883e8d4007f27f6d39f4a95a703bc572da4 Author: Xin LI <delphij@FreeBSD.org> AuthorDate: 2022-10-27 07:12:53 +0000 Commit: Xin LI <delphij@FreeBSD.org> CommitDate: 2022-10-30 19:43:13 +0000 MFV: Restore the ability to process files from stdin immediately. PR: bin/267221 Approved by: re (gjb) (cherry picked from commit 07dfb236c81483c2f08a3976f6d44ce307f4ceaf) (cherry picked from commit 97a6bb4a3f4712ec2d9443f79b6a6e8668ef2b38) --- 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,