]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/semctl.c
Linux: Fix __glibc_has_include use for <sys/stat.h> and statx
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / semctl.c
CommitLineData
04277e02 1/* Copyright (C) 1995-2019 Free Software Foundation, Inc.
3e5f5557
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
28f540f4 4
3e5f5557 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.
28f540f4 9
3e5f5557
UD
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.
28f540f4 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
28f540f4 18
d2f5be2a 19#include <sys/sem.h>
40c0a780 20#include <stdarg.h>
973209d8 21#include <ipc_priv.h>
e9dcb080 22#include <sysdep.h>
b5567b2a 23#include <shlib-compat.h>
40c0a780 24#include <errno.h>
973209d8 25
8be1539f
UD
26/* Define a `union semun' suitable for Linux here. */
27union semun
28{
29 int val; /* value for SETVAL */
30 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
31 unsigned short int *array; /* array for GETALL & SETALL */
32 struct seminfo *__buf; /* buffer for IPC_INFO */
33};
34
40c0a780
AZ
35#ifndef DEFAULT_VERSION
36# define DEFAULT_VERSION GLIBC_2_2
b5567b2a 37#endif
28f540f4 38
d2f5be2a 39int
40c0a780 40__new_semctl (int semid, int semnum, int cmd, ...)
d2f5be2a 41{
40c0a780 42 union semun arg = { 0 };
8be1539f
UD
43 va_list ap;
44
faaa6f62 45 /* Get the argument only if required. */
faaa6f62
UD
46 switch (cmd)
47 {
48 case SETVAL: /* arg.val */
49 case GETALL: /* arg.array */
50 case SETALL:
51 case IPC_STAT: /* arg.buf */
52 case IPC_SET:
53 case SEM_STAT:
54 case IPC_INFO: /* arg.__buf */
55 case SEM_INFO:
56 va_start (ap, cmd);
57 arg = va_arg (ap, union semun);
58 va_end (ap);
59 break;
60 }
8be1539f 61
40c0a780
AZ
62#ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
63 return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64,
64 arg.array);
65#else
66 return INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
67 SEMCTL_ARG_ADDRESS (arg));
b5567b2a 68#endif
40c0a780
AZ
69}
70versioned_symbol (libc, __new_semctl, semctl, DEFAULT_VERSION);
71
0482576e 72
40c0a780
AZ
73#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
74/* Since semctl use a variadic argument for semid_ds there is not need to
75 define and tie the compatibility symbol to the old 'union semun'
76 definition. */
0482576e 77int
40c0a780
AZ
78attribute_compat_text_section
79__old_semctl (int semid, int semnum, int cmd, ...)
0482576e 80{
40c0a780 81 union semun arg = { 0 };
0482576e
UD
82 va_list ap;
83
faaa6f62 84 /* Get the argument only if required. */
faaa6f62
UD
85 switch (cmd)
86 {
87 case SETVAL: /* arg.val */
88 case GETALL: /* arg.array */
89 case SETALL:
90 case IPC_STAT: /* arg.buf */
91 case IPC_SET:
92 case SEM_STAT:
93 case IPC_INFO: /* arg.__buf */
94 case SEM_INFO:
95 va_start (ap, cmd);
96 arg = va_arg (ap, union semun);
97 va_end (ap);
98 break;
99 }
0482576e 100
40c0a780
AZ
101# ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
102 return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd, arg.array);
103# else
104 return INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd,
105 SEMCTL_ARG_ADDRESS (arg));
106# endif
0482576e 107}
40c0a780
AZ
108compat_symbol (libc, __old_semctl, semctl, GLIBC_2_0);
109#endif