# HG changeset patch # User Sascha Wilde # Date 1395762332 -3600 # Node ID 70d627e9e80115884149b29f7f02da3851d25c1f # Parent 6fa0e12ae1d25c0731f957ab330205cdc125e441 New portability function to test if a file is an directory. diff -r 6fa0e12ae1d2 -r 70d627e9e801 common/portpath.c --- 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; +} diff -r 6fa0e12ae1d2 -r 70d627e9e801 common/portpath.h --- 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