# HG changeset patch # User Sascha Wilde # Date 1395749339 -3600 # Node ID f100861dad8f3f1f87e900a5f9cbdffbb4046f6e # Parent 92d7e0b408085cdf71cbab7c86d897b965b13f37 Added simple portable function to test if an file exists. diff -r 92d7e0b40808 -r f100861dad8f common/portpath.c --- a/common/portpath.c Tue Mar 25 12:54:47 2014 +0100 +++ b/common/portpath.c Tue Mar 25 13:08:59 2014 +0100 @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include char * @@ -31,3 +34,21 @@ return _fullpath(NULL, path, 0); #endif } + +bool +port_fileexits(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) + return true; + else + return false; +} diff -r 92d7e0b40808 -r f100861dad8f common/portpath.h --- a/common/portpath.h Tue Mar 25 12:54:47 2014 +0100 +++ b/common/portpath.h Tue Mar 25 13:08:59 2014 +0100 @@ -1,6 +1,8 @@ #ifndef PORTPATH_H #define PORTPATH_H +#include + /** * @file portpath.h * @brief Platform independent functions for file and path handling. @@ -28,4 +30,13 @@ */ char *port_realpath(char *path); +/** + * @brief test if a file exists + * @details uses a platform specific stat call to test if the given + * file exists. + * @param[in] path the path to the file + * @returns true if the file exists and false otherwise + */ +bool port_fileexits(char *path); + #endif