| 1 | //===---------- Linux implementation of the shm_open function -------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "src/sys/mman/shm_open.h" |
| 10 | #include "hdr/fcntl_macros.h" |
| 11 | #include "hdr/types/mode_t.h" |
| 12 | #include "src/__support/OSUtil/fcntl.h" |
| 13 | #include "src/__support/macros/config.h" |
| 14 | #include "src/sys/mman/linux/shm_common.h" |
| 15 | |
| 16 | namespace LIBC_NAMESPACE_DECL { |
| 17 | |
| 18 | static constexpr int DEFAULT_OFLAGS = O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK; |
| 19 | |
| 20 | LLVM_LIBC_FUNCTION(int, shm_open, (const char *name, int oflags, mode_t mode)) { |
| 21 | if (cpp::optional<shm_common::SHMPath> buffer = |
| 22 | shm_common::translate_name(name)) { |
| 23 | auto result = internal::open(buffer->data(), oflags | DEFAULT_OFLAGS, mode); |
| 24 | |
| 25 | if (!result.has_value()) { |
| 26 | libc_errno = result.error(); |
| 27 | return -1; |
| 28 | } |
| 29 | return result.value(); |
| 30 | } |
| 31 | return -1; |
| 32 | } |
| 33 | |
| 34 | } // namespace LIBC_NAMESPACE_DECL |
| 35 | |