From 75cb81d197c61b8465a1fd1c3eef807e22448df8 Mon Sep 17 00:00:00 2001 From: Tianyi Liu Date: Tue, 6 Feb 2024 15:03:46 +0800 Subject: [PATCH] sharedmem: Fix incorrect usages of `strerror` `strerror` takes the `errno` directly as its argument, negating it will result in an "Unknown error". Signed-off-by: Tianyi Liu --- sharedmem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sharedmem.c b/sharedmem.c index d8b5ecd..77fbcd4 100644 --- a/sharedmem.c +++ b/sharedmem.c @@ -418,7 +418,7 @@ static int rmtfs_mem_enumerate(struct rmtfs_mem *rmem) if (!dir) { fprintf(stderr, "Unable to open reserved-memory device tree node: %s\n", - strerror(-errno)); + strerror(errno)); close(basefd); return -1; } @@ -430,7 +430,7 @@ static int rmtfs_mem_enumerate(struct rmtfs_mem *rmem) dirfd = openat(basefd, de->d_name, O_DIRECTORY); if (dirfd < 0) { fprintf(stderr, "failed to open %s: %s\n", - de->d_name, strerror(-errno)); + de->d_name, strerror(errno)); ret = -1; goto out; } @@ -438,7 +438,7 @@ static int rmtfs_mem_enumerate(struct rmtfs_mem *rmem) regfd = openat(dirfd, "reg", O_RDONLY); if (regfd < 0) { fprintf(stderr, "failed to open reg of %s: %s\n", - de->d_name, strerror(-errno)); + de->d_name, strerror(errno)); ret = -1; goto out; } @@ -452,7 +452,7 @@ static int rmtfs_mem_enumerate(struct rmtfs_mem *rmem) rmem->size = be64toh(reg.qw[1]); } else { fprintf(stderr, "failed to read reg of %s: %s\n", - de->d_name, strerror(-errno)); + de->d_name, strerror(errno)); ret = -1; }