OSDN Git Service

51706c58d7e31b524d9714df4722f819fb9cdd98
[uclinux-h8/uClibc.git] / libc / misc / sysvipc / sem.c
1 /* 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 "ipc.h"
23
24
25 #ifdef L_semctl
26 /* Return identifier for array of NSEMS semaphores associated with
27    KEY.  */
28 #include <stdarg.h>
29 /* arg for semctl system calls. */
30 union semun {
31     int val;                    /* value for SETVAL */
32     struct semid_ds *buf;               /* buffer for IPC_STAT & IPC_SET */
33     unsigned short *array;              /* array for GETALL & SETALL */
34     struct seminfo *__buf;              /* buffer for IPC_INFO */
35     void *__pad;
36 };
37
38
39 #ifdef __NR_semctl
40 #define __NR___semctl __NR_semctl
41 static inline _syscall4(int, __semctl, int, semid, int, semnum, int, cmd, void *, arg);
42 #endif
43
44 int semctl(int semid, int semnum, int cmd, ...)
45 {
46     union semun arg;
47     va_list ap;
48
49     /* Get the argument.  */
50     va_start (ap, cmd);
51     arg = va_arg (ap, union semun);
52     va_end (ap);
53 #ifdef __NR_semctl
54     return __semctl(semid, semnum, cmd | __IPC_64, arg.__pad);
55 #else
56     return __syscall_ipc(IPCOP_semctl, semid, semnum, cmd | __IPC_64, &arg, 0);
57 #endif
58 }
59 #endif
60
61 #ifdef L_semget
62 /* for definition of NULL */
63 #include <stdlib.h>
64
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.  */
71 int 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.  */
85 int semop (int semid, struct sembuf *sops, size_t nsops)
86 {
87     return __syscall_ipc(IPCOP_semop, semid, (int) nsops, 0, sops, 0);
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
99 int 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, timeout);
103 }
104 #endif
105 #endif