about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-10-04 23:29:10 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-10-04 23:29:10 +0200
commitc135f989ec779f1f2d6438c2220156baaf616065 (patch)
tree70755c6727c3abf023b11e9d17545f97616d3163
parent5c77b97c35ceafc5c60c4e9a7a6e06d4bd253f3a (diff)
downloadprofani-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.
-rw-r--r--src/common.c12
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);
 }