[patch] Chane wfd to static variable in cat.c

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[patch] Chane wfd to static variable in cat.c

Nan Xiao-2
Hi tech@,

It seems "wfd" only need get its value when first calling "raw_cat", so
maybe a static variable should be better. Sorry if I am wrong.

Thanks!

Index: cat.c
===================================================================
RCS file: /cvs/src/bin/cat/cat.c,v
retrieving revision 1.26
diff -u -p -r1.26 cat.c
--- cat.c 19 Oct 2016 18:20:25 -0000 1.26
+++ cat.c 11 Apr 2018 10:05:05 -0000
@@ -223,14 +223,14 @@ raw_args(char **argv)
 void
 raw_cat(int rfd)
 {
- int wfd;
+ static int wfd;
  ssize_t nr, nw, off;
  static size_t bsize;
  static char *buf = NULL;
  struct stat sbuf;

- wfd = fileno(stdout);
  if (buf == NULL) {
+ wfd = fileno(stdout);
  if (fstat(wfd, &sbuf))
  err(1, "stdout");
  bsize = MAXIMUM(sbuf.st_blksize, BUFSIZ);
--
Best Regards
Nan Xiao(肖楠)