From: Jason Ish Date: Thu, 4 Jan 2018 17:11:06 +0000 (-0600) Subject: SCPathExists - function to see if a path exists X-Git-Tag: suricata-4.1.0-beta1~346 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38bbdb51d5c102a8f376df943d2f6b5f5de81ab6;p=thirdparty%2Fsuricata.git SCPathExists - function to see if a path exists Returns true if path exists, otherwise false. --- diff --git a/src/util-path.c b/src/util-path.c index d2989946b9..f4ba183264 100644 --- a/src/util-path.c +++ b/src/util-path.c @@ -120,3 +120,20 @@ int SCCreateDirectoryTree(const char *path, const bool final) return 0; } + +/** + * \brief Check if a path exists. + * + * \param Path to check for existence + * + * \retval true if path exists + * \retval false if path does not exist + */ +bool SCPathExists(const char *path) +{ + struct stat sb; + if (stat(path, &sb) == 0) { + return true; + } + return false; +} diff --git a/src/util-path.h b/src/util-path.h index f425092e64..aeffe2c787 100644 --- a/src/util-path.h +++ b/src/util-path.h @@ -35,5 +35,6 @@ int PathIsAbsolute(const char *); int PathIsRelative(const char *); int SCDefaultMkDir(const char *path); int SCCreateDirectoryTree(const char *path, const bool final); +bool SCPathExists(const char *path); #endif /* __UTIL_PATH_H__ */