1f6f42af0SSchrodinger ZHU Yifan //===---------- Linux implementation of the shm_open function -------------===// 2f6f42af0SSchrodinger ZHU Yifan // 3f6f42af0SSchrodinger ZHU Yifan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4f6f42af0SSchrodinger ZHU Yifan // See https://llvm.org/LICENSE.txt for license information. 5f6f42af0SSchrodinger ZHU Yifan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6f6f42af0SSchrodinger ZHU Yifan // 7f6f42af0SSchrodinger ZHU Yifan //===----------------------------------------------------------------------===// 8f6f42af0SSchrodinger ZHU Yifan 9f6f42af0SSchrodinger ZHU Yifan #include "src/sys/mman/shm_open.h" 10*7b663bd9SJob Henandez Lara #include "hdr/types/mode_t.h" 115ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 12f6f42af0SSchrodinger ZHU Yifan #include "src/fcntl/open.h" 13f6f42af0SSchrodinger ZHU Yifan #include "src/sys/mman/linux/shm_common.h" 14f6f42af0SSchrodinger ZHU Yifan 155ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 16f6f42af0SSchrodinger ZHU Yifan 17f6f42af0SSchrodinger ZHU Yifan static constexpr int DEFAULT_OFLAGS = O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK; 18f6f42af0SSchrodinger ZHU Yifan 19f6f42af0SSchrodinger ZHU Yifan LLVM_LIBC_FUNCTION(int, shm_open, (const char *name, int oflags, mode_t mode)) { 20f6f42af0SSchrodinger ZHU Yifan using namespace shm_common; 21f6f42af0SSchrodinger ZHU Yifan if (cpp::optional<SHMPath> buffer = translate_name(name)) 22f6f42af0SSchrodinger ZHU Yifan return open(buffer->data(), oflags | DEFAULT_OFLAGS, mode); 23f6f42af0SSchrodinger ZHU Yifan return -1; 24f6f42af0SSchrodinger ZHU Yifan } 25f6f42af0SSchrodinger ZHU Yifan 265ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 27