changeset 176:70d627e9e801

New portability function to test if a file is an directory.
author Sascha Wilde <wilde@intevation.de>
date Tue, 25 Mar 2014 16:45:32 +0100
parents 6fa0e12ae1d2
children c92297bcda8f
files common/portpath.c common/portpath.h
diffstat 2 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/common/portpath.c	Tue Mar 25 16:31:52 2014 +0100
+++ b/common/portpath.c	Tue Mar 25 16:45:32 2014 +0100
@@ -60,3 +60,21 @@
   else
     return false;
 }
+
+bool
+port_isdir(char *path)
+{
+  int ret;
+#ifndef _WIN32
+  struct stat sb;
+  ret = stat(path, &sb);
+#else
+  struct _stat sb;
+  ret = _stat(path, &sb);
+#endif
+
+  if ((ret == 0) && S_ISDIR(sb.st_mode))
+    return true;
+  else
+    return false;
+}
--- a/common/portpath.h	Tue Mar 25 16:31:52 2014 +0100
+++ b/common/portpath.h	Tue Mar 25 16:45:32 2014 +0100
@@ -39,4 +39,13 @@
  */
 bool port_fileexits(char *path);
 
+/**
+ * @brief test if a file is a directory
+ * @details uses a platform specific stat call to test if the given
+ * file is an directory.
+ * @param[in] path the path to the file
+ * @returns true if the file is an directory and false otherwise
+ */
+bool port_isdir(char *path);
+
 #endif

http://wald.intevation.org/projects/trustbridge/