summaryrefslogtreecommitdiffhomepage
path: root/loader/filesystem.cpp
blob: aeec8954c33ad92816ec93194269266af782bb03 (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
#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 {

namespace Unicode = Corrade::Utility::Unicode;

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