etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libc / sys / shmat.c
blob66466d952b63e60ecc1654801f60f780a3229e8a
1 #define _SYSTEM 1
2 #define _MINIX_SYSTEM 1
4 #include <sys/cdefs.h>
5 #include <lib.h>
6 #include "namespace.h"
8 #include <minix/rs.h>
10 #include <lib.h>
11 #include <sys/types.h>
12 #include <sys/ipc.h>
13 #include <sys/shm.h>
14 #include <stdlib.h>
15 #include <errno.h>
16 #include <string.h>
18 static int get_ipc_endpt(endpoint_t *pt)
20 return minix_rs_lookup("ipc", pt);
23 /* Attach shared memory segment. */
24 void *shmat(int shmid, const void *shmaddr, int shmflg)
26 message m;
27 endpoint_t ipc_pt;
28 int r;
30 if (get_ipc_endpt(&ipc_pt) != OK) {
31 errno = ENOSYS;
32 return NULL;
35 memset(&m, 0, sizeof(m));
36 m.m_lc_ipc_shmat.id = shmid;
37 m.m_lc_ipc_shmat.addr = shmaddr;
38 m.m_lc_ipc_shmat.flag = shmflg;
40 r = _syscall(ipc_pt, IPC_SHMAT, &m);
41 if (r != OK)
42 return (void *) -1;
43 return m.m_lc_ipc_shmat.retaddr;
46 /* Deattach shared memory segment. */
47 int shmdt(const void *shmaddr)
49 message m;
50 endpoint_t ipc_pt;
52 if (get_ipc_endpt(&ipc_pt) != OK) {
53 errno = ENOSYS;
54 return -1;
57 memset(&m, 0, sizeof(m));
58 m.m_lc_ipc_shmdt.addr = shmaddr;
60 return _syscall(ipc_pt, IPC_SHMDT, &m);