summaryrefslogtreecommitdiff
path: root/minix/lib/libc/sys/shmget.c
blob: 5cb373daf131b1de018151ae0625f4fa4277ba40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#define _SYSTEM	1

#include <sys/cdefs.h>
#include <lib.h>
#include "namespace.h"

#include <minix/rs.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

static int get_ipc_endpt(endpoint_t *pt)
{
	return minix_rs_lookup("ipc", pt);
}

/* Get shared memory segment. */
int shmget(key_t key, size_t size, int shmflg)
{
	message m;
	endpoint_t ipc_pt;
	int r;

	if (get_ipc_endpt(&ipc_pt) != OK) {
		errno = ENOSYS;
		return -1;
	}

	memset(&m, 0, sizeof(m));
	m.m_lc_ipc_shmget.key = key;
	m.m_lc_ipc_shmget.size = size;
	m.m_lc_ipc_shmget.flag = shmflg;

	r = _syscall(ipc_pt, IPC_SHMGET, &m);
	if (r != OK)
		return r;
	return m.m_lc_ipc_shmget.retid;
}