| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "files/public/c/lib/singletons.h" | |
| 6 | |
| 7 #include <errno.h> | |
| 8 | |
| 9 #include "files/public/c/lib/directory_wrapper.h" | |
| 10 #include "files/public/c/lib/fd_table.h" | |
| 11 #include "files/public/c/lib/real_errno_impl.h" | |
| 12 #include "files/public/c/mojio_config.h" | |
| 13 #include "mojo/public/cpp/environment/logging.h" | |
| 14 | |
| 15 namespace mojio { | |
| 16 namespace singletons { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 RealErrnoImpl* g_errno_impl = nullptr; | |
| 21 FDTable* g_fd_table = nullptr; | |
| 22 DirectoryWrapper* g_current_working_directory = nullptr; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 ErrnoImpl* GetErrnoImpl() { | |
| 27 if (!g_errno_impl) | |
| 28 g_errno_impl = new RealErrnoImpl(); // Does NOT modify errno. | |
| 29 return g_errno_impl; | |
| 30 } | |
| 31 | |
| 32 void ResetErrnoImpl() { | |
| 33 delete g_errno_impl; // Does NOT modify errno. | |
| 34 g_errno_impl = nullptr; | |
| 35 } | |
| 36 | |
| 37 FDTable* GetFDTable() { | |
| 38 ErrnoImpl::Setter errno_setter(GetErrnoImpl()); // Protect errno. | |
| 39 if (!g_fd_table) | |
| 40 g_fd_table = new FDTable(GetErrnoImpl(), MOJIO_CONFIG_MAX_NUM_FDS); | |
| 41 return g_fd_table; | |
| 42 } | |
| 43 | |
| 44 void ResetFDTable() { | |
| 45 ErrnoImpl::Setter errno_setter(GetErrnoImpl()); // Protect errno. | |
| 46 delete g_fd_table; | |
| 47 g_fd_table = nullptr; | |
| 48 } | |
| 49 | |
| 50 void SetCurrentWorkingDirectory(mojo::files::DirectoryPtr directory) { | |
| 51 delete g_current_working_directory; | |
| 52 g_current_working_directory = | |
| 53 new DirectoryWrapper(GetErrnoImpl(), directory.Pass()); | |
| 54 } | |
| 55 | |
| 56 DirectoryWrapper* GetCurrentWorkingDirectory() { | |
| 57 ErrnoImpl::Setter errno_setter(GetErrnoImpl()); | |
| 58 if (!g_current_working_directory) { | |
| 59 // TODO(vtl): Ponder this error code. (This is, e.g., what openat() would | |
| 60 // return if its dirfd were not valid.) | |
| 61 errno_setter.Set(EBADF); | |
| 62 MOJO_LOG(ERROR) << "No current working directory"; | |
| 63 return nullptr; | |
| 64 } | |
| 65 | |
| 66 return g_current_working_directory; | |
| 67 } | |
| 68 | |
| 69 void ResetCurrentWorkingDirectory() { | |
| 70 ErrnoImpl::Setter errno_setter(GetErrnoImpl()); // Protect errno. | |
| 71 delete g_current_working_directory; | |
| 72 g_current_working_directory = nullptr; | |
| 73 } | |
| 74 | |
| 75 } // namespace singletons | |
| 76 } // namespace mojio | |
| OLD | NEW |