From 18710989429b077577954671f1f71fbd8298a3e2 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Thu, 6 Feb 2025 11:28:49 +0100 Subject: [PATCH] print strerror descriptions in error messages instead of errno --- ethercat.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ethercat.c b/ethercat.c index e2e4193..0c38366 100644 --- a/ethercat.c +++ b/ethercat.c @@ -51,23 +51,23 @@ int main(int argc, char** argv) { } if (freopen(NULL, "rb", stdin) == NULL) { - fprintf(stderr, "Failed to set stdin to binary mode: %i\n", errno); + fprintf(stderr, "Failed to set stdin to binary mode: %s\n", strerror(errno)); return EXIT_RUNTIME; } stdin_dup = dup(fileno(stdin)); if (stdin_dup == -1) { - fprintf(stderr, "Failed to dup() stdin: %i\n", errno); + fprintf(stderr, "Failed to dup() stdin: %s\n", strerror(errno)); } if (freopen(NULL, "wb", stdout) == NULL) { - fprintf(stderr, "Failed to set stdout to binary mode: %i\n", errno); + fprintf(stderr, "Failed to set stdout to binary mode: %s\n", strerror(errno)); return EXIT_RUNTIME; } file_descriptor = open(DEVICE_NODE_TUN, O_RDWR | O_NONBLOCK); if (file_descriptor == -1) { - fprintf(stderr, "Failed to open %s: %i\n", DEVICE_NODE_TUN, errno); + fprintf(stderr, "Failed to open %s: %s\n", DEVICE_NODE_TUN, strerror(errno)); return EXIT_RUNTIME; } @@ -76,7 +76,7 @@ int main(int argc, char** argv) { strncpy(ifr.ifr_name, argv[1], IFNAMSIZ); if (ioctl(file_descriptor, TUNSETIFF, &ifr) == -1) { - fprintf(stderr, "An error occurred while trying to ioctl: %i\n", errno); + fprintf(stderr, "An error occurred while trying to ioctl: %s\n", strerror(errno)); close(file_descriptor); return EXIT_RUNTIME; } @@ -90,7 +90,7 @@ int main(int argc, char** argv) { while (fcntl(file_descriptor, F_GETFD) != -1 && !stop_now) { read_size = read(file_descriptor, buffer, BUFFER_SIZE); if (read_size == -1) { - fprintf(stderr, "Failed to read from tap: %i\n", errno); + fprintf(stderr, "Failed to read from tap: %s\n", strerror(errno)); yeet(file_descriptor); return EXIT_RUNTIME; } @@ -102,7 +102,7 @@ int main(int argc, char** argv) { // using read_size as the amount of remaining bytes write_size = write(fileno(stdout), buffer, read_size); if (write_size == -1) { - fprintf(stderr, "Failed to write stdout: %i\n", errno); + fprintf(stderr, "Failed to write stdout: %s\n", strerror(errno)); yeet(file_descriptor); return EXIT_RUNTIME; } @@ -110,7 +110,7 @@ int main(int argc, char** argv) { just_created_dup = false; read_size = read(stdin_dup, buffer, BUFFER_SIZE); if (read_size == -1) { - fprintf(stderr, "Failed to read from stdin: %i\n", errno); + fprintf(stderr, "Failed to read from stdin: %s\n", strerror(errno)); yeet(file_descriptor); return EXIT_RUNTIME; } @@ -125,7 +125,7 @@ int main(int argc, char** argv) { ) { write_size = write(file_descriptor, buffer, read_size); if (write_size == -1) { - fprintf(stderr, "Failed to write stdout: %i\n", errno); + fprintf(stderr, "Failed to write stdout: %s\n", strerror(errno)); yeet(file_descriptor); return EXIT_RUNTIME; }