diff options
author | Amit Kucheria <amit.kucheria@linaro.org> | 2014-05-30 14:02:53 +0530 |
---|---|---|
committer | Amit Kucheria <amit.kucheria@linaro.org> | 2014-06-03 19:19:24 +0530 |
commit | 37a681fa82ce7280433a3f5817c39f1d0aee7f6b (patch) | |
tree | f96ffeb18ae78afaeec0fd9aa0fd39a79c477f2b | |
parent | 9c3290bbf227b4917dceb8295b78721c4af7f4b6 (diff) |
Print more details when fopen fails
Useful for tracking down why the following command fails:
sudo ./idlestat -o /tmp/newfile
where, newfile doesn't already exist
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r-- | idlestat.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -749,8 +749,10 @@ static struct cpuidle_datas *idlestat_load(const char *path) int ret; f = fopen(path, "r"); - if (!f) - return ptrerror("fopen"); + if (!f) { + fprintf(stderr, "%s: failed to open '%s': %m\n", __func__, path); + return NULL; + } /* version line */ fgets(buffer, BUFSIZE, f); @@ -1055,7 +1057,7 @@ static int idlestat_file_for_each_line(const char *path, void *data, f = fopen(path, "r"); if (!f) { - fprintf(stderr, "failed to open '%s': %m\n", path); + fprintf(stderr, "%s: failed to open '%s': %m\n", __func__, path); return -1; } @@ -1080,8 +1082,9 @@ static int idlestat_store(const char *path) return -1; f = fopen(path, "w+"); + if (!f) { - fprintf(f, "failed to open '%s': %m\n", path); + fprintf(f, "%s: failed to open '%s': %m\n", __func__, path); return -1; } |