summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-03-06 03:25:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-03-06 03:25:41 +0000
commitfac369db6751a95cd8f6d9c0b8ecf4db583605ac (patch)
tree393bff82ce0051373bc01d73046a2da00225d7d7 /util.c
parentReleasing debian version 4.2+20230227-1. (diff)
downloadmdadm-fac369db6751a95cd8f6d9c0b8ecf4db583605ac.tar.xz
mdadm-fac369db6751a95cd8f6d9c0b8ecf4db583605ac.zip
Merging upstream version 4.2+20230302.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'util.c')
-rw-r--r--util.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/util.c b/util.c
index 8c7f3fd..7fc881b 100644
--- a/util.c
+++ b/util.c
@@ -2401,3 +2401,48 @@ void sleep_for(unsigned int sec, long nsec, bool wake_after_interrupt)
}
} while (!wake_after_interrupt && errno == EINTR);
}
+
+/* is_directory() - Checks if directory provided by path is indeed a regular directory.
+ * @path: directory path to be checked
+ *
+ * Doesn't accept symlinks.
+ *
+ * Return: true if is a directory, false if not
+ */
+bool is_directory(const char *path)
+{
+ struct stat st;
+
+ if (lstat(path, &st) != 0) {
+ pr_err("%s: %s\n", strerror(errno), path);
+ return false;
+ }
+
+ if (!S_ISDIR(st.st_mode))
+ return false;
+
+ return true;
+}
+
+/*
+ * is_file() - Checks if file provided by path is indeed a regular file.
+ * @path: file path to be checked
+ *
+ * Doesn't accept symlinks.
+ *
+ * Return: true if is a file, false if not
+ */
+bool is_file(const char *path)
+{
+ struct stat st;
+
+ if (lstat(path, &st) != 0) {
+ pr_err("%s: %s\n", strerror(errno), path);
+ return false;
+ }
+
+ if (!S_ISREG(st.st_mode))
+ return false;
+
+ return true;
+}