semget.c 518 字节
Newer Older
R
Rich Felker 已提交
1
#include <sys/sem.h>
2 3
#include <limits.h>
#include <errno.h>
R
Rich Felker 已提交
4 5 6 7 8
#include "syscall.h"
#include "ipc.h"

int semget(key_t key, int n, int fl)
{
9 10 11 12 13
	/* The kernel uses the wrong type for the sem_nsems member
	 * of struct semid_ds, and thus might not check that the
	 * n fits in the correct (per POSIX) userspace type, so
	 * we have to check here. */
	if (n > USHRT_MAX) return __syscall_ret(-EINVAL);
14
#ifndef SYS_ipc
15
	return syscall(SYS_semget, key, n, fl);
R
Rich Felker 已提交
16
#else
17
	return syscall(SYS_ipc, IPCOP_semget, key, n, fl);
R
Rich Felker 已提交
18 19
#endif
}