[LEDE-DEV] [PATCH] ubox: Replace strerror(errno) with %m format.

Rosen Penev rosenp at gmail.com
Sat Jan 13 12:46:04 PST 2018


Saves 872 bytes on Ubuntu 16.04. No change in functionality.

Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
 getrandom.c   | 4 ++--
 log/logd.c    | 2 +-
 log/logread.c | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/getrandom.c b/getrandom.c
index 73a37b0..ad3a7af 100644
--- a/getrandom.c
+++ b/getrandom.c
@@ -50,9 +50,9 @@ int main(int argc, char *argv[])
 		if (nbtot <= sizeof(buf))
 			len = nbtot;
 		if (syscall(SYS_getrandom, buf, len, 0) == -1)
-			ERROR_EXIT("getrandom() failed: %s\n", strerror(errno));
+			ERROR_EXIT("getrandom() failed: %m\n");
 		if (write(STDOUT_FILENO, buf, len) != len)
-			ERROR_EXIT("write() failed: %s\n", strerror(errno));
+			ERROR_EXIT("write() failed: %m\n");
 		nbtot -= sizeof(buf);
 	}
 
diff --git a/log/logd.c b/log/logd.c
index 9931723..18788fe 100644
--- a/log/logd.c
+++ b/log/logd.c
@@ -119,7 +119,7 @@ read_log(struct ubus_context *ctx, struct ubus_object *obj,
 	l = log_list(count, NULL);
 	if (stream) {
 		if (pipe(fds) == -1) {
-			fprintf(stderr, "logd: failed to create pipe: %s\n", strerror(errno));
+			fprintf(stderr, "logd: failed to create pipe: %m\n");
 			return -1;
 		}
 
diff --git a/log/logread.c b/log/logread.c
index 784d1f9..d85e03c 100644
--- a/log/logread.c
+++ b/log/logread.c
@@ -78,7 +78,7 @@ static void log_handle_reconnect(struct uloop_timeout *timeout)
 {
 	sender.fd = usock((log_udp) ? (USOCK_UDP) : (USOCK_TCP), log_ip, log_port);
 	if (sender.fd < 0) {
-		fprintf(stderr, "failed to connect: %s\n", strerror(errno));
+		fprintf(stderr, "failed to connect: %m\n");
 		uloop_timeout_set(&retry, 1000);
 	} else {
 		uloop_fd_add(&sender, ULOOP_READ);
@@ -126,7 +126,7 @@ static int log_notify(struct blob_attr *msg)
 		}
 		sender.fd = open(log_file, O_CREAT | O_WRONLY | O_APPEND, 0600);
 		if (sender.fd < 0) {
-			fprintf(stderr, "failed to open %s: %s\n", log_file, strerror(errno));
+			fprintf(stderr, "failed to open %s: %m\n", log_file);
 			exit(-1);
 		}
 	}
@@ -358,7 +358,7 @@ int main(int argc, char **argv)
 			log_type = LOG_FILE;
 			sender.fd = open(log_file, O_CREAT | O_WRONLY| O_APPEND, 0600);
 			if (sender.fd < 0) {
-				fprintf(stderr, "failed to open %s: %s\n", log_file, strerror(errno));
+				fprintf(stderr, "failed to open %s: %m\n", log_file);
 				exit(-1);
 			}
 		} else {
-- 
2.7.4




More information about the Lede-dev mailing list