6#if defined(DART_HOST_OS_FUCHSIA)
13#include <lib/fdio/namespace.h>
14#include <zircon/status.h>
24 : fdio_ns_(fdio_ns), cwd_(
strdup(
"/")) {
25 rootfd_ = fdio_ns_opendir(fdio_ns);
27 FATAL(
"Failed to open file descriptor for namespace: errno=%d: %s", errno,
30 cwdfd_ = dup(rootfd_);
32 FATAL(
"Failed to dup() namespace file descriptor: errno=%d: %s", errno,
37NamespaceImpl::NamespaceImpl(
const char* path)
38 : fdio_ns_(nullptr), cwd_(
strdup(
"/")) {
41 FATAL(
"Failed to open file descriptor for namespace: errno=%d: %s", errno,
44 cwdfd_ = dup(rootfd_);
46 FATAL(
"Failed to dup() namespace file descriptor: errno=%d: %s", errno,
51NamespaceImpl::~NamespaceImpl() {
55 if (fdio_ns_ !=
nullptr) {
56 zx_status_t status = fdio_ns_destroy(fdio_ns_);
57 if (status != ZX_OK) {
58 Syslog::PrintErr(
"fdio_ns_destroy: %s\n", zx_status_get_string(status));
63bool NamespaceImpl::SetCwd(Namespace* namespc,
const char* new_path) {
64 NamespaceScope ns(namespc, new_path);
65 const intptr_t new_cwdfd =
73 if (!File::IsAbsolutePath(new_path)) {
76 tbuf.AddString(File::PathSeparator());
77 tbuf.AddString(ns.path());
81 const intptr_t result_len =
95Namespace* Namespace::Create(intptr_t namespc) {
96 NamespaceImpl* namespc_impl =
nullptr;
97 if (namespc !=
kNone) {
98 namespc_impl =
new NamespaceImpl(
reinterpret_cast<fdio_ns_t*
>(namespc));
100 return new Namespace(namespc_impl);
103Namespace* Namespace::Create(
const char* path) {
104 return new Namespace(
new NamespaceImpl(path));
107Namespace::~Namespace() {
111intptr_t Namespace::Default() {
115const char* Namespace::GetCurrent(Namespace* namespc) {
116 if (Namespace::IsDefault(namespc)) {
121 return DartUtils::ScopedCopyCString(
buffer);
123 return namespc->namespc()->cwd();
126bool Namespace::SetCurrent(Namespace* namespc,
const char* path) {
127 if (Namespace::IsDefault(namespc)) {
130 return namespc->namespc()->SetCwd(namespc, path);
133void Namespace::ResolvePath(Namespace* namespc,
136 const char** resolved_path) {
138 ASSERT(resolved_path !=
nullptr);
139 if (Namespace::IsDefault(namespc)) {
141 *resolved_path =
path;
144 if (File::IsAbsolutePath(path)) {
145 *dirfd = namespc->namespc()->rootfd();
146 if (strcmp(path, File::PathSeparator()) == 0) {
148 *resolved_path =
".";
151 *resolved_path = &
path[1];
154 *dirfd = namespc->namespc()->cwdfd();
155 *resolved_path =
path;
159NamespaceScope::NamespaceScope(Namespace* namespc,
const char* path) {
160 Namespace::ResolvePath(namespc, path, &fd_, &path_);
163NamespaceScope::~NamespaceScope() {}
NamespaceImpl(fdio_ns_t *fdio_ns)
static const uint8_t buffer[]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
char * strdup(const char *str1)
#define NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)