summaryrefslogtreecommitdiffhomepage
path: root/loader/filesystem.cpp
blob: 785ef4145e0724e2de9a11989442b8a6b46bd053 (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
28
29
30
31
32
33
34
35
36
37
38
#include "impl.hpp"
#include "compat/assert.hpp"
#include <cerrno>
#include <Corrade/Containers/StringView.h>
#include <Corrade/Utility/Debug.h>
#include <Corrade/Utility/Implementation/ErrorString.h>
#ifdef _WIN32
#include <Corrade/Containers/Array.h>
#include <Corrade/Utility/Unicode.h>
#include <direct.h>
#else
#include <unistd.h>
#endif

namespace floormat::loader_detail {

#ifdef _WIN32
namespace Unicode = Corrade::Utility::Unicode;
#endif

bool chdir(StringView pathname)
{
    int ret;
#ifdef _WIN32
    ret = _wchdir(Unicode::widen(pathname));
#else
    ret = chdir(pathname.data());
#endif
    if (ret)
    {
        Error err;
        err << "chdir: can't change directory to" << pathname << Error::nospace << ':';
        Corrade::Utility::Implementation::printErrnoErrorString(err, errno);
    }
    return !ret;
}

} // namespace floormat::loader_detail