summaryrefslogtreecommitdiffhomepage
path: root/compat/os-file.cpp
blob: 0d8f95c20ee8d5496e76b3eeb5dfefaf05c2e5ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "os-file.hpp"
#include "assert.hpp"
#include <cerrno>
#include <cr/StringView.h>

#ifdef _WIN32
#include <io.h>
#define fm_os_access _access
#else
#include <unistd.h>
#define fm_os_access access
#endif

namespace floormat::fs {

bool file_exists(StringView name)
{
    fm_assert(name.flags() & StringViewFlag::NullTerminated);
    fm_debug_assert(!name.find('\0'));
    if (!fm_os_access(name.data(), F_OK))
        return true;
    int error = errno;
    // just let it die if the file exists but can't be accessed
    return error != ENOENT;
}

} // namespace floormat::fs