HOG2
utils
FileUtil.cpp
Go to the documentation of this file.
1
/*
2
* $Id: FileUtil.cpp
3
* hog2
4
*
5
* Created by Junwen Shen on 4/25/23.
6
*
7
* This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
8
*
9
*/
10
11
#include "
FileUtil.h
"
12
13
#if __cplusplus < 201703L // C++17
14
15
#include <sys/stat.h>
16
17
// Windows doesn't have S_ISDIR or S_ISREG
18
#ifndef S_ISDIR
19
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
20
#endif
21
#ifndef S_ISREG
22
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
23
#endif
24
25
#else
26
#include <filesystem>
27
#endif
28
29
bool
FileExists
(
const
std::string &filename) {
30
#if __cplusplus < 201703L
31
struct
stat buffer{};
32
return
stat(filename.c_str(), &buffer) == 0 &&
S_ISREG
(buffer.st_mode);
33
#else
34
return
std::filesystem::is_regular_file(filename);
35
#endif
36
}
FileExists
bool FileExists(const std::string &filename)
Check if a file exists.
Definition:
FileUtil.cpp:29
FileUtil.h
S_ISREG
#define S_ISREG(mode)
Definition:
FileUtil.cpp:22
Generated by
1.8.17