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:
+3
-2
@@ -214,9 +214,10 @@ show_cnt(const char *file, uintmax_t linect, uintmax_t wordct,
|
|||||||
static int
|
static int
|
||||||
cnt(const char *file)
|
cnt(const char *file)
|
||||||
{
|
{
|
||||||
char buf[MAXBSIZE], *p;
|
static char buf[MAXBSIZE];
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
mbstate_t mbs;
|
mbstate_t mbs;
|
||||||
|
const char *p;
|
||||||
uintmax_t linect, wordct, charct, llct, tmpll;
|
uintmax_t linect, wordct, charct, llct, tmpll;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
size_t clen;
|
size_t clen;
|
||||||
@@ -259,7 +260,7 @@ cnt(const char *file)
|
|||||||
* lines than to get words, since the word count requires locale
|
* lines than to get words, since the word count requires locale
|
||||||
* handling.
|
* handling.
|
||||||
*/
|
*/
|
||||||
while ((len = read(fd, buf, sizeof(buf)))) {
|
while ((len = read(fd, buf, sizeof(buf))) != 0) {
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
xo_warn("%s: read", file);
|
xo_warn("%s: read", file);
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user