All of lore.kernel.org
 help / color / mirror / Atom feed
From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: Alejandro Colomar <alx.manpages@gmail.com>
Cc: linux-man@vger.kernel.org
Subject: [PATCH 2/3] tee.2: use proper types in example, declare variables at point-of-use
Date: Mon, 3 Jan 2022 16:34:02 +0100	[thread overview]
Message-ID: <2b35693db4d1e63c41b0decf949d08f1966e7ad7.1641224016.git.nabijaczleweli@nabijaczleweli.xyz> (raw)
In-Reply-To: <a59610f1d397bf532e4ce46481f439ac089fb05e.1641224016.git.nabijaczleweli@nabijaczleweli.xyz>

[-- Attachment #1: Type: text/plain, Size: 1555 bytes --]

---
 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;
-- 
2.30.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-01-03 15:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 15:33 [PATCH 1/3] tee.2: ffix наб
2022-01-03 15:34 ` наб [this message]
2022-01-03 16:25   ` [PATCH 2/3] tee.2: use proper types in example, declare variables at point-of-use Alejandro Colomar (man-pages)
2022-01-03 15:34 ` [PATCH 3/3] tee.2: always fail after perror(), use for(;;) instead of do{}while(1) наб
2022-01-03 16:40   ` Alejandro Colomar (man-pages)
2022-01-03 17:03     ` [PATCH v2 2/4] tee.2: use proper types in example наб
2022-01-03 17:27       ` Alejandro Colomar (man-pages)
2022-01-03 17:35         ` наб
2022-01-03 17:51           ` Alejandro Colomar (man-pages)
2022-01-03 17:03     ` [PATCH v2 3/4] tee.2: use for(;;) instead of do{}while(1) наб
2022-01-03 17:03     ` [PATCH v2 4/4] tee.2: always fail after perror() in example наб
2022-01-03 16:49 ` [PATCH 1/3] tee.2: ffix Alejandro Colomar (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b35693db4d1e63c41b0decf949d08f1966e7ad7.1641224016.git.nabijaczleweli@nabijaczleweli.xyz \
    --to=nabijaczleweli@nabijaczleweli.xyz \
    --cc=alx.manpages@gmail.com \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.