From a23ce913585ac65765fccf9cd770e0213d9e7a4a Mon Sep 17 00:00:00 2001 From: Simon Lieb Date: Fri, 11 Feb 2022 18:15:32 +0100 Subject: [PATCH] check chdir(2) & freopen(3) errors --- stt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stt.c b/stt.c index 3a35f4b..1ca4ece 100644 --- a/stt.c +++ b/stt.c @@ -72,8 +72,9 @@ opentimesfile() //oldcwd = dirfd(opendir(".")); passwd = getpwuid(getuid()); - chdir(passwd->pw_dir); - + if (chdir(passwd->pw_dir) == -1) { + perror("chdir failed"); + } fp = fopen(timesfile, "a+"); if (fp == NULL) { @@ -377,7 +378,9 @@ default: changed = 1; } if (changed) { - freopen(timesfile, "w", fp); + if (freopen(timesfile, "w", fp) == NULL) { + perror("reopen failed"); + } writetimes(fp, timestree); } if (list) {