diff options
author | Aaron Marcher <me@drkhsh.at> | 2018-03-28 19:46:27 +0200 |
---|---|---|
committer | Aaron Marcher <me@drkhsh.at> | 2018-03-28 19:46:27 +0200 |
commit | faa52bdcc0221de2d8fae950e409a8ac5e05bfcd (patch) | |
tree | 7e1641219e1d65d82f8e5467a1a599d11fd6164c /components/swap.c | |
parent | 2289798b6d3565d96cc81d5208c50afa2010e296 (diff) |
Format error messages properly
Make use of strerror(errno) and format all errors equally:
function ['parameters']: error message
Diffstat (limited to 'components/swap.c')
-rw-r--r-- | components/swap.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/components/swap.c b/components/swap.c index b82ff46..f3bbeb2 100644 --- a/components/swap.c +++ b/components/swap.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #if defined(__linux__) +#include <errno.h> #include <stdio.h> #include <string.h> @@ -15,12 +16,12 @@ swap_free(void) fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(stderr, "Failed to open file /proc/meminfo"); + fprintf(stderr, "fopen '/proc/meminfo': %s\n", strerror(errno)); return NULL; } if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) { - fprintf(stderr, "swap_free: read error"); + fprintf(stderr, "fread '/proc/meminfo': %s\n", strerror(errno)); fclose(fp); return NULL; } @@ -47,12 +48,12 @@ swap_perc(void) fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(stderr, "Failed to open file /proc/meminfo"); + fprintf(stderr, "fopen '/proc/meminfo': %s\n", strerror(errno)); return NULL; } if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) { - fprintf(stderr, "swap_perc: read error"); + fprintf(stderr, "fread '/proc/meminfo': %s\n", strerror(errno)); fclose(fp); return NULL; } @@ -83,11 +84,11 @@ swap_total(void) fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(stderr, "Failed to open file /proc/meminfo"); + fprintf(stderr, "fopen '/proc/meminfo': %s\n", strerror(errno)); return NULL; } if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) { - fprintf(stderr, "swap_total: read error"); + fprintf(stderr, "fread '/proc/meminfo': %s\n", strerror(errno)); fclose(fp); return NULL; } @@ -110,11 +111,11 @@ swap_used(void) fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - fprintf(stderr, "Failed to open file /proc/meminfo"); + fprintf(stderr, "fopen '/proc/meminfo': %s\n", strerror(errno)); return NULL; } if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) { - fprintf(stderr, "swap_used: read error"); + fprintf(stderr, "fread '/proc/meminfo': %s\n", strerror(errno)); fclose(fp); return NULL; } |