From dc546649fd0d07427d9efa21d8eb193c67acf412 Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 6 Apr 2017 17:47:25 -0500 Subject: [PATCH] Make sure directory exists and is a real directory --- os/utils.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/os/utils.c b/os/utils.c index 5a6cafc..2a15724 100644 --- a/os/utils.c +++ b/os/utils.c @@ -74,12 +74,22 @@ int os_utils_file_exists(const char* file_name) { return 0; } +/*** + * See if the passed in directory exists, and is a directory + * @param directory_name the name to examine + * @returns true(1) if it exists, false(0) if not + */ int os_utils_directory_exists(const char* directory_name) { - if (access(directory_name, F_OK) != -1) + if (access(directory_name, F_OK) != -1 && os_utils_is_directory(directory_name)) return 1; return 0; } +/** + * Determine if the passed in file name is a directory + * @param file_name the file name + * @returns true(1) if file_name is a directory + */ int os_utils_is_directory(const char* file_name) { struct stat path_stat; stat(file_name, &path_stat);