Re: [PATCH 2/3] tee.2: use proper types in example, declare variables at point-of-use

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, наб!

I like the change to use ssize_t, but I prefer C89 declarations of top of the function, with the only exception of C99 loop iterators, which we do use. Could you please change the patch accordingly?

Thanks,

Alex

On 1/3/22 16:34, наб wrote:
---
  man2/tee.2 | 14 +++++---------
  1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/man2/tee.2 b/man2/tee.2
index 14a927c93..17b93882d 100644
--- a/man2/tee.2
+++ b/man2/tee.2
@@ -163,15 +163,12 @@ Tue Oct 28 10:06:00 CET 2014
  int
  main(int argc, char *argv[])
  {
-    int fd;
-    int len, slen;
-
      if (argc != 2) {
          fprintf(stderr, "Usage: %s <file>\en", argv[0]);
          exit(EXIT_FAILURE);
      }
- fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
+    int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
      if (fd == \-1) {
          perror("open");
          exit(EXIT_FAILURE);
@@ -181,9 +178,8 @@ main(int argc, char *argv[])
          /*
           * tee stdin to stdout.
           */
-        len = tee(STDIN_FILENO, STDOUT_FILENO,
-                  INT_MAX, SPLICE_F_NONBLOCK);
-
+        ssize_t len = tee(STDIN_FILENO, STDOUT_FILENO,
+                          INT_MAX, SPLICE_F_NONBLOCK);
          if (len < 0) {
              if (errno == EAGAIN)
                  continue;
@@ -197,8 +193,8 @@ main(int argc, char *argv[])
           * Consume stdin by splicing it to a file.
           */
          while (len > 0) {
-            slen = splice(STDIN_FILENO, NULL, fd, NULL,
-                          len, SPLICE_F_MOVE);
+            ssize_t slen = splice(STDIN_FILENO, NULL, fd, NULL,
+                                  len, SPLICE_F_MOVE);
              if (slen < 0) {
                  perror("splice");
                  break;

--
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux