]> git.ipfire.org Git - thirdparty/glibc.git/blame - rt/shm_open.c
sparc (64bit): Regenerate ulps
[thirdparty/glibc.git] / rt / shm_open.c
CommitLineData
b7a0bfbd 1/* shm_open -- open a POSIX shared memory object. Generic POSIX file version.
6d7e8eda 2 Copyright (C) 2001-2023 Free Software Foundation, Inc.
a63be9f7
UD
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
a63be9f7
UD
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
a63be9f7 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
a63be9f7
UD
18
19#include <errno.h>
b7a0bfbd 20#include <fcntl.h>
c6e7ec2f 21#include <not-cancel.h>
b7a0bfbd 22#include <pthread.h>
c6e7ec2f 23#include <shlib-compat.h>
b7a0bfbd
FW
24#include <shm-directory.h>
25#include <unistd.h>
a63be9f7
UD
26
27/* Open shared memory object. */
28int
c6e7ec2f 29__shm_open (const char *name, int oflag, mode_t mode)
a63be9f7 30{
b7a0bfbd
FW
31 struct shmdir_name dirname;
32 if (__shm_get_name (&dirname, name, false) != 0)
33 {
34 __set_errno (EINVAL);
35 return -1;
36 }
37
38 oflag |= O_NOFOLLOW | O_CLOEXEC;
39
c6e7ec2f 40 int fd = __open64_nocancel (dirname.name, oflag, mode);
b7a0bfbd
FW
41 if (fd == -1 && __glibc_unlikely (errno == EISDIR))
42 /* It might be better to fold this error with EINVAL since
43 directory names are just another example for unsuitable shared
44 object names and the standard does not mention EISDIR. */
45 __set_errno (EINVAL);
46
b7a0bfbd 47 return fd;
a63be9f7 48}
c6e7ec2f
FW
49versioned_symbol (libc, __shm_open, shm_open, GLIBC_2_34);
50
51#if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
52compat_symbol (libc, __shm_open, shm_open, GLIBC_2_2);
53#endif