check chdir(2) & freopen(3) errors

This commit is contained in:
Simon Lieb 2022-02-11 18:15:32 +01:00
parent ddf9b11261
commit a23ce91358

9
stt.c
View file

@ -72,8 +72,9 @@ opentimesfile()
//oldcwd = dirfd(opendir(".")); //oldcwd = dirfd(opendir("."));
passwd = getpwuid(getuid()); passwd = getpwuid(getuid());
chdir(passwd->pw_dir); if (chdir(passwd->pw_dir) == -1) {
perror("chdir failed");
}
fp = fopen(timesfile, "a+"); fp = fopen(timesfile, "a+");
if (fp == NULL) { if (fp == NULL) {
@ -377,7 +378,9 @@ default:
changed = 1; changed = 1;
} }
if (changed) { if (changed) {
freopen(timesfile, "w", fp); if (freopen(timesfile, "w", fp) == NULL) {
perror("reopen failed");
}
writetimes(fp, timestree); writetimes(fp, timestree);
} }
if (list) { if (list) {