Util-Linux package development
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 11/12] write: improve coding style
Date: Sun, 15 May 2016 18:03:24 +0100 (BST)	[thread overview]
Message-ID: <alpine.LNX.2.20.1605151800570.592@imuri> (raw)
In-Reply-To: <20160511085420.y6menmghp6qydbac@ws.net.home>

On Wed, 11 May 2016, Karel Zak wrote:

> You do not need the crazy macro at all
> 
>    while (*s) {
>         int rc = 0;
>         int c = *s++;
> 
>         if (c == '\n')
>             rc = fputc_careful('\n', stdout, '^');
>         if (rc == 0)
>             rc = fputc_careful(c, stdout, '^');
>         if (rc == EOF)
>             err(EXIT_FAILURE, _("carefulputc failed"));
>    }

The commit is amended in spirit of 'no macro at all'. The code is not 
exactly the same as above.

https://github.com/kerolasa/lelux-utiliteetit/commit/cbae2781ab82cd641ef1839f9fec71fe984322ff

-- snip
From: Sami Kerola <kerolasa@iki.fi>
Date: Sat, 14 May 2016 16:40:45 +0100
Subject: [PATCH 11/15] write: remove PUTC macro

Function like macros make following the execution flow unnecessarily
difficult, and deserves to be removed.

Requested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/write.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/term-utils/write.c b/term-utils/write.c
index 57b2254..3b86694 100644
--- a/term-utils/write.c
+++ b/term-utils/write.c
@@ -220,18 +220,17 @@ static void signal_handler(int signo)
  */
 static void write_line(char *s)
 {
-	char c;
-
-#define	PUTC(c)	if (fputc_careful(c, stdout, '^') == EOF) \
-    err(EXIT_FAILURE, _("carefulputc failed"));
 	while (*s) {
-		c = *s++;
-		if (c == '\n')
-			PUTC('\r');
-		PUTC(c);
+		const int c = *s++;
+
+		if (c == '\n') {
+			if (fputc_careful('\r', stdout, '^') == EOF)
+				goto fail;
+		}
+		if (fputc_careful(c, stdout, '^') == EOF)
+ fail:
+			err(EXIT_FAILURE, _("carefulputc failed"));
 	}
-	return;
-#undef PUTC
 }
 
 /*
-- 
2.8.2
-- snip

-- 
Sami Kerola
http://www.iki.fi/kerolasa/

  reply	other threads:[~2016-05-15 17:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-09 21:27 [PATCH 00/12] pull: write(1) improvements Sami Kerola
2016-05-09 21:27 ` [PATCH 01/12] write: remove unused variable Sami Kerola
2016-05-09 21:27 ` [PATCH 02/12] write: get rid of function prototypes Sami Kerola
2016-05-09 21:27 ` [PATCH 03/12] write: remove pointless fileno(3) calls Sami Kerola
2016-05-09 21:27 ` [PATCH 04/12] write: set atime value in term_chk() only if needed Sami Kerola
2016-05-09 21:27 ` [PATCH 05/12] write: use xstrncpy() from strutils.h Sami Kerola
2016-05-09 21:27 ` [PATCH 06/12] write: run atexit() checks at the end of execution Sami Kerola
2016-05-09 21:27 ` [PATCH 07/12] write: add control structure to clarify what is going on Sami Kerola
2016-05-11  8:38   ` Karel Zak
2016-05-15 17:00     ` Sami Kerola
2016-05-09 21:27 ` [PATCH 08/12] write: improve variable names Sami Kerola
2016-05-09 21:27 ` [PATCH 09/12] write: remove unnecessary utmp variables Sami Kerola
2016-05-09 21:27 ` [PATCH 10/12] write: make timestamp to be obviously just a clock time Sami Kerola
2016-05-09 21:27 ` [PATCH 11/12] write: improve coding style Sami Kerola
2016-05-11  8:54   ` Karel Zak
2016-05-15 17:03     ` Sami Kerola [this message]
2016-05-09 21:27 ` [PATCH 12/12] write: tell when effective gid and tty path group mismatch Sami Kerola
2016-05-10 14:24   ` Benno Schulenberg
2016-05-10 19:37     ` Sami Kerola

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=alpine.LNX.2.20.1605151800570.592@imuri \
    --to=kerolasa@iki.fi \
    --cc=kzak@redhat.com \
    --cc=util-linux@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox