]> git.saurik.com Git - apple/libc.git/blob - sys/semctl.c
Libc-391.5.21.tar.gz
[apple/libc.git] / sys / semctl.c
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #include <unistd.h>
24 #include <stdarg.h>
25 #include <sys/sem.h>
26 #include <sys/syscall.h>
27
28 /*
29 * Stub function to account for the differences in the ipc_perm structure,
30 * while maintaining binary backward compatibility.
31 */
32 int
33 semctl(int semid, int semnum, int cmd, ...)
34 {
35 #ifdef __DARWIN_UNIX03
36 va_list ap;
37 struct __semid_ds_new *ds;
38
39 va_start(ap, cmd);
40 ds = va_arg(ap, struct __semid_ds_new *);
41 va_end(ap);
42
43 return syscall(SYS_semctl, semid, semnum, cmd, ds);
44 #else /* !__DARWIN_UNIX03 */
45 va_list ap;
46 struct __semid_ds_old *ds_old;
47 struct __semid_ds_new ds;
48 struct __semid_ds_new *ds_new = &ds;
49 int rv;
50
51 va_start(ap, cmd);
52 ds_old = va_arg(ap, struct __semid_ds_old *);
53 va_end(ap);
54
55 #define _UP_CVT(x) ds_new-> x = ds_old-> x
56 #define _DN_CVT(x) ds_old-> x = ds_new-> x
57
58 if (cmd == IPC_SET) {
59 /* convert before call */
60 _UP_CVT(sem_perm.uid);
61 _UP_CVT(sem_perm.gid);
62 _UP_CVT(sem_perm.cuid);
63 _UP_CVT(sem_perm.cgid);
64 _UP_CVT(sem_perm.mode);
65 ds_new->sem_perm._seq = ds_old->sem_perm.seq;
66 ds_new->sem_perm._key = ds_old->sem_perm.key;
67 _UP_CVT(sem_base);
68 _UP_CVT(sem_nsems);
69 _UP_CVT(sem_otime);
70 _UP_CVT(sem_pad1); /* binary compatibility */
71 _UP_CVT(sem_ctime);
72 _UP_CVT(sem_pad2); /* binary compatibility */
73 _UP_CVT(sem_pad3[0]); /* binary compatibility */
74 _UP_CVT(sem_pad3[1]); /* binary compatibility */
75 _UP_CVT(sem_pad3[2]); /* binary compatibility */
76 _UP_CVT(sem_pad3[3]); /* binary compatibility */
77 }
78
79 rv = syscall(SYS_semctl, semid, semnum, cmd, &ds);
80
81 if (cmd == IPC_STAT) {
82 /* convert after call */
83 _DN_CVT(sem_perm.uid); /* warning! precision loss! */
84 _DN_CVT(sem_perm.gid); /* warning! precision loss! */
85 _DN_CVT(sem_perm.cuid); /* warning! precision loss! */
86 _DN_CVT(sem_perm.cgid); /* warning! precision loss! */
87 _DN_CVT(sem_perm.mode);
88 ds_new->sem_perm.seq = ds_old->sem_perm._seq;
89 ds_new->sem_perm.key = ds_old->sem_perm._key;
90 _DN_CVT(sem_base);
91 _DN_CVT(sem_nsems);
92 _DN_CVT(sem_otime);
93 _DN_CVT(sem_pad1); /* binary compatibility */
94 _DN_CVT(sem_ctime);
95 _DN_CVT(sem_pad2); /* binary compatibility */
96 _DN_CVT(sem_pad3[0]); /* binary compatibility */
97 _DN_CVT(sem_pad3[1]); /* binary compatibility */
98 _DN_CVT(sem_pad3[2]); /* binary compatibility */
99 _DN_CVT(sem_pad3[3]); /* binary compatibility */
100 }
101
102 return (rv);
103 #endif /* !__DARWIN_UNIX03 */
104 }