~aleteoryx/muditaos

ref: 1d2f5cf7a49cf1fb9463d289daa1492a2bec2d1d muditaos/module-vfs/src/purefs/fs/filesystem_cwd.cpp -rw-r--r-- 910 bytes
1d2f5cf7 — Piotr Tański [EGD-7754] Dates bumped in disclaimers 4 years ago
                                                                                
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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <purefs/fs/filesystem.hpp>
#include <purefs/fs/thread_local_cwd.hpp>
#include <unistd.h>

namespace purefs::fs
{
    auto filesystem::getcwd() noexcept -> std::string_view
    {
        return internal::get_thread_local_cwd_path();
    }
    auto filesystem::chdir(std::string_view name) noexcept -> int
    {
        struct stat sts;
        int ret;
        ret = this->stat(name, sts);
        if (ret) {
            return ret;
        }
        if ((sts.st_mode & S_IFMT) != S_IFDIR) {
            return -ENOTDIR;
        }
        const auto abspath = absolute_path(name);
        ret                = internal::set_thread_cwd_path(abspath);
        return ret;
    }
} // namespace purefs::fs