MFV: Restore the ability to process files from stdin immediately.
PR: bin/267221 MFC after: 3 days
This commit is contained in:
commit
07dfb236c8
@ -1,5 +1,5 @@
|
|||||||
.\" $File: file.man,v 1.144 2021/02/05 22:08:31 christos Exp $
|
.\" $File: file.man,v 1.146 2022/10/26 16:56:14 christos Exp $
|
||||||
.Dd February 5, 2021
|
.Dd October 26, 2022
|
||||||
.Dt FILE __CSECTION__
|
.Dt FILE __CSECTION__
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -512,11 +512,8 @@ unwrap(struct magic_set *ms, const char *fn)
|
|||||||
size_t llen = 0;
|
size_t llen = 0;
|
||||||
int wid = 0, cwid;
|
int wid = 0, cwid;
|
||||||
int e = 0;
|
int e = 0;
|
||||||
size_t fi = 0, fimax = 100;
|
size_t fi = 0, fimax = 0;
|
||||||
char **flist = CAST(char **, malloc(sizeof(*flist) * fimax));
|
char **flist = NULL;
|
||||||
|
|
||||||
if (flist == NULL)
|
|
||||||
out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list");
|
|
||||||
|
|
||||||
if (strcmp("-", fn) == 0)
|
if (strcmp("-", fn) == 0)
|
||||||
f = stdin;
|
f = stdin;
|
||||||
@ -530,27 +527,38 @@ out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list");
|
|||||||
while ((len = getline(&line, &llen, f)) > 0) {
|
while ((len = getline(&line, &llen, f)) > 0) {
|
||||||
if (line[len - 1] == '\n')
|
if (line[len - 1] == '\n')
|
||||||
line[len - 1] = '\0';
|
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) {
|
if (fi >= fimax) {
|
||||||
fimax += 100;
|
fimax += 100;
|
||||||
char **nf = CAST(char **,
|
char **nf = CAST(char **,
|
||||||
realloc(flist, fimax * sizeof(*flist)));
|
realloc(flist, fimax * sizeof(*flist)));
|
||||||
if (nf == NULL)
|
if (nf == NULL) {
|
||||||
goto out;
|
file_err(EXIT_FAILURE,
|
||||||
|
"Cannot allocate memory for file list");
|
||||||
|
}
|
||||||
flist = nf;
|
flist = nf;
|
||||||
}
|
}
|
||||||
flist[fi++] = line;
|
flist[fi++] = line;
|
||||||
cwid = file_mbswidth(ms, line);
|
|
||||||
if (cwid > wid)
|
|
||||||
wid = cwid;
|
|
||||||
line = NULL;
|
line = NULL;
|
||||||
llen = 0;
|
llen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!nobuffer) {
|
||||||
fimax = fi;
|
fimax = fi;
|
||||||
for (fi = 0; fi < fimax; fi++) {
|
for (fi = 0; fi < fimax; fi++) {
|
||||||
e |= process(ms, flist[fi], wid);
|
e |= process(ms, flist[fi], wid);
|
||||||
free(flist[fi]);
|
free(flist[fi]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
free(flist);
|
free(flist);
|
||||||
|
|
||||||
if (f != stdin)
|
if (f != stdin)
|
||||||
|
Loading…
Reference in New Issue
Block a user