39 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/sys/mman/shm_open.h"10 11#include "hdr/fcntl_macros.h"12#include "hdr/types/mode_t.h"13#include "src/__support/OSUtil/fcntl.h"14#include "src/__support/libc_errno.h"15#include "src/__support/macros/config.h"16#include "src/sys/mman/linux/shm_common.h"17 18namespace LIBC_NAMESPACE_DECL {19 20static constexpr int DEFAULT_OFLAGS = O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK;21 22LLVM_LIBC_FUNCTION(int, shm_open, (const char *name, int oflags, mode_t mode)) {23 auto path_result = shm_common::translate_name(name);24 if (!path_result.has_value()) {25 libc_errno = path_result.error();26 return -1;27 }28 29 auto open_result =30 internal::open(path_result->data(), oflags | DEFAULT_OFLAGS, mode);31 if (!open_result.has_value()) {32 libc_errno = open_result.error();33 return -1;34 }35 return open_result.value();36}37 38} // namespace LIBC_NAMESPACE_DECL39