blob: cca4cdfccc97075338886cd1b961c46cd4878cd8 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
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
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#include <errno.h>
21#include <sys/sem.h>
22#include <stddef.h>
23#include <stdlib.h> /* for NULL */
24
25#include "ipc.h"
26
27
28#ifdef L_semctl
29/* Return identifier for array of NSEMS semaphores associated with
30 KEY. */
31#include <stdarg.h>
32/* arg for semctl system calls. */
33union semun {
34 int val; /* value for SETVAL */
35 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
36 unsigned short *array; /* array for GETALL & SETALL */
37 struct seminfo *__buf; /* buffer for IPC_INFO */
38 void *__pad;
39};
40
41
42#ifdef __NR_semctl
43#define __NR___semctl __NR_semctl
44static __inline__ _syscall4(int, __semctl, int, semid, int, semnum, int, cmd, void *, arg)
45#endif
46
47int semctl(int semid, int semnum, int cmd, ...)
48{
49 union semun arg;
50 va_list ap;
51
52 /* Get the argument. */
53 va_start (ap, cmd);
54 arg = va_arg (ap, union semun);
55 va_end (ap);
56#ifdef __NR_semctl
57 return __semctl(semid, semnum, cmd | __IPC_64, arg.__pad);
58#else
59 return __syscall_ipc(IPCOP_semctl, semid, semnum, cmd|__IPC_64, &arg, NULL);
60#endif
61}
62#endif
63
64#ifdef L_semget
65#ifdef __NR_semget
66_syscall3(int, semget, key_t, key, int, nsems, int, semflg)
67
68#else
69/* Return identifier for array of NSEMS semaphores associated
70 * with KEY. */
71int semget (key_t key, int nsems, int semflg)
72{
73 return __syscall_ipc(IPCOP_semget, key, nsems, semflg, NULL, 0);
74}
75#endif
76#endif
77
78#ifdef L_semop
79
80#ifdef __NR_semop
81_syscall3(int, semop, int, semid, struct sembuf *, sops, size_t, nsops)
82
83#else
84/* Perform user-defined atomical operation of array of semaphores. */
85int semop (int semid, struct sembuf *sops, size_t nsops)
86{
87 return __syscall_ipc(IPCOP_semop, semid, (int) nsops, 0, sops, NULL);
88}
89#endif
90#endif
91
92#ifdef L_semtimedop
93
94#ifdef __NR_semtimedop
95_syscall4(int, semtimedop, int, semid, struct sembuf *, sops, size_t, nsops, const struct timespec *, timeout)
96
97#else
98
99int semtimedop(int semid, struct sembuf *sops, size_t nsops,
100 const struct timespec *timeout)
101{
102 return __syscall_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, (void *) timeout);
103}
104#endif
105#endif