| 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/mojio_fcntl.h" | |
| 6 | |
| 7 #include <stdarg.h> | |
| 8 | |
| 9 #include <memory> | |
| 10 #include <utility> | |
| 11 | |
| 12 #include "files/public/c/lib/directory_wrapper.h" | |
| 13 #include "files/public/c/lib/fd_impl.h" | |
| 14 #include "files/public/c/lib/fd_table.h" | |
| 15 #include "files/public/c/lib/singletons.h" | |
| 16 | |
| 17 namespace mojio { | |
| 18 namespace { | |
| 19 | |
| 20 int OpenImpl(const char* path, int oflag, mojio_mode_t mode) { | |
| 21 DirectoryWrapper* cwd = singletons::GetCurrentWorkingDirectory(); | |
| 22 if (!cwd) | |
| 23 return -1; | |
| 24 | |
| 25 std::unique_ptr<FDImpl> fd_impl(cwd->Open(path, oflag, mode)); | |
| 26 if (!fd_impl) | |
| 27 return -1; | |
| 28 | |
| 29 return singletons::GetFDTable()->Add(std::move(fd_impl)); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 } // namespace mojio | |
| 34 | |
| 35 extern "C" { | |
| 36 | |
| 37 int mojio_creat(const char* path, mojio_mode_t mode) { | |
| 38 // This is defined by POSIX. | |
| 39 return mojio::OpenImpl(path, MOJIO_O_WRONLY | MOJIO_O_CREAT | MOJIO_O_TRUNC, | |
| 40 mode); | |
| 41 } | |
| 42 | |
| 43 int mojio_open(const char* path, int oflag, ...) { | |
| 44 va_list ap; | |
| 45 mojio_mode_t mode = 0; | |
| 46 if ((oflag & MOJIO_O_CREAT)) { | |
| 47 va_start(ap, oflag); | |
| 48 mode = va_arg(ap, mojio_mode_t); | |
| 49 va_end(ap); | |
| 50 } | |
| 51 return mojio::OpenImpl(path, oflag, mode); | |
| 52 } | |
| 53 | |
| 54 } // extern "C" | |
| OLD | NEW |