wc: Make the read buffer static.
The read buffer in cnt() is 64 kB, which is a bit excessive for a stack variable. MAXBSIZE has grown since this code was originally written, and it might grow again in the future. Since the program is single-threaded and cnt() does not recurse, we can safely make the buffer static. While there, constify p since it is only used to read. Sponsored by: Klara, Inc. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D38608
This commit is contained in:
parent
5c870e1b48
commit
5016d112ad
@ -214,9 +214,10 @@ show_cnt(const char *file, uintmax_t linect, uintmax_t wordct,
|
||||
static int
|
||||
cnt(const char *file)
|
||||
{
|
||||
char buf[MAXBSIZE], *p;
|
||||
static char buf[MAXBSIZE];
|
||||
struct stat sb;
|
||||
mbstate_t mbs;
|
||||
const char *p;
|
||||
uintmax_t linect, wordct, charct, llct, tmpll;
|
||||
ssize_t len;
|
||||
size_t clen;
|
||||
@ -259,7 +260,7 @@ cnt(const char *file)
|
||||
* lines than to get words, since the word count requires locale
|
||||
* handling.
|
||||
*/
|
||||
while ((len = read(fd, buf, sizeof(buf)))) {
|
||||
while ((len = read(fd, buf, sizeof(buf))) != 0) {
|
||||
if (len < 0) {
|
||||
xo_warn("%s: read", file);
|
||||
(void)close(fd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user