~aleteoryx/muditaos

ref: 6bd165c4d9946a30a9a2e4a3f882160fd6bf5f17 muditaos/module-vfs/src/purefs/fs/filesystem_cwd.cpp -rw-r--r-- 910 bytes
6bd165c4 — Marcin Smoczyński [EGD-6715] Add chapter bsp to the code owners 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-2020, 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