From: Sami Kerola Date: Sun, 22 Jun 2014 22:43:09 +0000 (+0100) Subject: logger: refactor long if clause X-Git-Tag: v2.26-rc1~576^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c462a8caf2b885df4a8e769d9056d8f63b82f6be;p=thirdparty%2Futil-linux.git logger: refactor long if clause When if clause that continues throughout whole function it usually can be shorten to immediate action, e.g., in this case return on the spot not at end of the function. Signed-off-by: Sami Kerola --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index 5204cef55f..9f9650c317 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -273,24 +273,22 @@ static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg) char buf[1000], pid[30], *cp, *tp; time_t now; - if (fd > -1) { - if (logflags & LOG_PID) - snprintf(pid, sizeof(pid), "[%d]", getpid()); - else - pid[0] = 0; - if (tag) - cp = tag; - else - cp = xgetlogin(); - time(&now); - tp = ctime(&now) + 4; - - snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s", - pri, tp, cp, pid, msg); - - if (write_all(fd, buf, strlen(buf) + 1) < 0) - warn(_("write failed")); - } + if (fd < 0) + return; + if (logflags & LOG_PID) + snprintf(pid, sizeof(pid), "[%d]", getpid()); + else + pid[0] = 0; + if (tag) + cp = tag; + else + cp = xgetlogin(); + time(&now); + tp = ctime(&now) + 4; + snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s", + pri, tp, cp, pid, msg); + if (write_all(fd, buf, strlen(buf) + 1) < 0) + warn(_("write failed")); } static void __attribute__ ((__noreturn__)) usage(FILE *out)