| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #include "files/c/mojio_fcntl.h" |
| #include "files/c/lib/directory_wrapper.h" |
| #include "files/c/lib/fd_impl.h" |
| #include "files/c/lib/fd_table.h" |
| #include "files/c/lib/singletons.h" |
| int OpenImpl(const char* path, int oflag, mojio_mode_t mode) { |
| DirectoryWrapper* cwd = singletons::GetCurrentWorkingDirectory(); |
| std::unique_ptr<FDImpl> fd_impl(cwd->Open(path, oflag, mode)); |
| return singletons::GetFDTable()->Add(std::move(fd_impl)); |
| int mojio_creat(const char* path, mojio_mode_t mode) { |
| // This is defined by POSIX. |
| return mojio::OpenImpl(path, MOJIO_O_WRONLY | MOJIO_O_CREAT | MOJIO_O_TRUNC, |
| int mojio_open(const char* path, int oflag, ...) { |
| if ((oflag & MOJIO_O_CREAT)) { |
| mode = va_arg(ap, mojio_mode_t); |
| return mojio::OpenImpl(path, oflag, mode); |