From 0c883ab44675a3e4baa06d03a53f70908601cd20 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 Mar 2023 04:25:37 +0100 Subject: Adding upstream version 4.2+20230302. Signed-off-by: Daniel Baumann --- util.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'util.c') 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; +} -- cgit v1.2.3