From: Timo Kokkonen Date: Tue, 27 Mar 2012 18:15:13 +0000 (+0300) Subject: Replace strerror() with "%m" at printf X-Git-Url: http://git.itanic.dy.fi/?p=glucose;a=commitdiff_plain;h=449770ae304a3c5ee656c0c6e50eb90bdcec1255 Replace strerror() with "%m" at printf The printf functions already support printing the errno value as a string, there is no need to convert it manually. Signed-off-by: Timo Kokkonen --- diff --git a/hiddev.c b/hiddev.c index 048e3b1..8cf4e5a 100644 --- a/hiddev.c +++ b/hiddev.c @@ -52,7 +52,7 @@ int hiddev_read(unsigned char *data, int bufsize, int fd) int hiddev_write(const unsigned char data[64], int fd , int usage_code) { - int rc = 0, uindex, error; + int rc = 0, uindex; struct hiddev_usage_ref uref; struct hiddev_report_info rinfo; @@ -84,8 +84,7 @@ int hiddev_write(const unsigned char data[64], int fd , int usage_code) err2: printf("HIDIOCSREPORT\n"); err: - error = errno; - printf("Error in IOCTL: %s\n", strerror(error)); + printf("Error in IOCTL: %m\n"); return rc; } @@ -93,7 +92,7 @@ err: static int get_usagecode(int fd) { struct hiddev_usage_ref uref; - int rc, error; + int rc; uref.report_type = HID_REPORT_TYPE_OUTPUT; uref.report_id = 0x0; @@ -102,8 +101,7 @@ static int get_usagecode(int fd) rc = ioctl(fd, HIDIOCGUCODE, &uref); if (rc < 0) { - error = errno; - printf("Error gettin usage code: %s\n", strerror(error)); + printf("Error gettin usage code: %m\n"); return rc; } @@ -190,8 +188,8 @@ int hiddev_open_by_id(int vendor_id, int product_id, int *usage_code) dir = opendir(HIDDEV_PATH); if (dir == NULL) { error = errno; - trace(4, "Failed to open directory %s: %s\n", HIDDEV_PATH, - strerror(error)); + trace(4, "Failed to open directory %s: %m\n", HIDDEV_PATH); + return -error; } @@ -215,8 +213,8 @@ int hiddev_open_by_id(int vendor_id, int product_id, int *usage_code) if (errno) { error = errno; - trace(0, "Error reading directory %s: %s\n", HIDDEV_PATH, - strerror(error)); + trace(0, "Error reading directory %s: %m\n", HIDDEV_PATH); + return -error; } diff --git a/main.c b/main.c index a78d680..449fa15 100644 --- a/main.c +++ b/main.c @@ -138,7 +138,7 @@ static int dump_entries(struct user_options *opts, int fd, int usage_code) int main(int argc, char *argv[]) { struct user_options opts; - int fd, usage_code, ret, error; + int fd, usage_code, ret; bzero(&opts, sizeof(opts)); opts.output_format = CLEAN; @@ -151,9 +151,8 @@ int main(int argc, char *argv[]) if (opts.output_path) { opts.outf = fopen(opts.output_path, "w"); if (opts.outf == NULL) { - error = errno; - trace(0, "Failed to open output file %s: %s\n", - opts.output_path, strerror(error)); + trace(0, "Failed to open output file \"%s\": %m\n", + opts.output_path); return 1; } } else {