]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: refactor long if clause
authorSami Kerola <kerolasa@iki.fi>
Sun, 22 Jun 2014 22:43:09 +0000 (23:43 +0100)
committerSami Kerola <kerolasa@iki.fi>
Mon, 28 Jul 2014 20:15:17 +0000 (21:15 +0100)
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 <kerolasa@iki.fi>
misc-utils/logger.c

index 5204cef55f26990c8364a1487c4a12cb869bc7ad..9f9650c317ae706b35fafe3b72f9cb37e62a8b37 100644 (file)
@@ -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)