X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=blobdiff_plain;f=src%2Fgromacs%2Futility%2Fpath.cpp;h=60c0e0cd7adbb164f5c3a1ad20f47f7762e71b16;hb=1d597ac0415f9a847715ef65daa55fe1312bd59f;hp=d6aa17140d65db27cd77cd0f31ef291dd0a6903a;hpb=8bb9e38caa59684b3731a434a603c78beaf9a87a;p=alexxy%2Fgromacs.git diff --git a/src/gromacs/utility/path.cpp b/src/gromacs/utility/path.cpp index d6aa17140d..60c0e0cd7a 100644 --- a/src/gromacs/utility/path.cpp +++ b/src/gromacs/utility/path.cpp @@ -47,10 +47,12 @@ #include #include +#include #include #include #include +#include #include @@ -386,6 +388,44 @@ std::string Path::resolveSymlinks(const std::string &path) return result; } +/******************************************************************** + * File + */ + +// static +bool File::exists(const char *filename) +{ + if (filename == NULL) + { + return false; + } + FILE *test = std::fopen(filename, "r"); + if (test == NULL) + { + return false; + } + else + { + std::fclose(test); + // Windows doesn't allow fopen of directory, so we don't need to check + // this separately. +#ifndef GMX_NATIVE_WINDOWS + struct stat st_buf; + int status = stat(filename, &st_buf); + if (status != 0 || !S_ISREG(st_buf.st_mode)) + { + return false; + } +#endif + return true; + } +} + +// static +bool File::exists(const std::string &filename) +{ + return exists(filename.c_str()); +} /******************************************************************** * Directory