]>
Commit | Line | Data |
---|---|---|
b7a0bfbd | 1 | /* shm_open -- open a POSIX shared memory object. Generic POSIX file version. |
dff8da6b | 2 | Copyright (C) 2001-2024 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> | |
a979b727 | 26 | #include <sys/mman.h> |
a63be9f7 UD |
27 | |
28 | /* Open shared memory object. */ | |
29 | int | |
c6e7ec2f | 30 | __shm_open (const char *name, int oflag, mode_t mode) |
a63be9f7 | 31 | { |
b7a0bfbd | 32 | struct shmdir_name dirname; |
0b7bf0e0 | 33 | int ret =__shm_get_name (&dirname, name, false); |
34 | if (ret != 0) | |
b7a0bfbd | 35 | { |
0b7bf0e0 | 36 | __set_errno (ret); |
b7a0bfbd FW |
37 | return -1; |
38 | } | |
39 | ||
40 | oflag |= O_NOFOLLOW | O_CLOEXEC; | |
a979b727 SB |
41 | #if defined (SHM_ANON) && defined (O_TMPFILE) |
42 | if (name == SHM_ANON) | |
43 | oflag |= O_TMPFILE; | |
44 | #endif | |
b7a0bfbd | 45 | |
c6e7ec2f | 46 | int fd = __open64_nocancel (dirname.name, oflag, mode); |
b7a0bfbd FW |
47 | if (fd == -1 && __glibc_unlikely (errno == EISDIR)) |
48 | /* It might be better to fold this error with EINVAL since | |
49 | directory names are just another example for unsuitable shared | |
50 | object names and the standard does not mention EISDIR. */ | |
51 | __set_errno (EINVAL); | |
52 | ||
b7a0bfbd | 53 | return fd; |
a63be9f7 | 54 | } |
c6e7ec2f FW |
55 | versioned_symbol (libc, __shm_open, shm_open, GLIBC_2_34); |
56 | ||
57 | #if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34) | |
58 | compat_symbol (libc, __shm_open, shm_open, GLIBC_2_2); | |
59 | #endif |