diff options
author | Michael Vetter <jubalh@iodoru.org> | 2019-10-04 23:29:10 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2019-10-04 23:29:10 +0200 |
commit | c135f989ec779f1f2d6438c2220156baaf616065 (patch) | |
tree | 70755c6727c3abf023b11e9d17545f97616d3163 /src | |
parent | 5c77b97c35ceafc5c60c4e9a7a6e06d4bd253f3a (diff) | |
download | profani-tty-c135f989ec779f1f2d6438c2220156baaf616065.tar.gz |
Check errors in is_dir() is_regular_file()
In case of error print the error. And return right value. Improvement based on @pasis advice in https://github.com/profanity-im/profanity/pull/1036 Applying in preparation to merge that PR.
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/common.c b/src/common.c index 2a4da006..d8ee9915 100644 --- a/src/common.c +++ b/src/common.c @@ -443,7 +443,11 @@ int is_regular_file(const char *path) { struct stat st; - stat(path, &st); + int ret = stat(path, &st); + if (ret != 0) { + perror(NULL); + return 0; + } return S_ISREG(st.st_mode); } @@ -451,7 +455,11 @@ int is_dir(const char *path) { struct stat st; - stat(path, &st); + int ret = stat(path, &st); + if (ret != 0) { + perror(NULL); + return 0; + } return S_ISDIR(st.st_mode); } |