1 /* Function ShmCreate Create a SysV shared memory segment */
2 void * ShmCreate(key_t ipc_key, int shm_size, int perm, int fill)
5 int shm_id; /* ID of the IPC shared memory segment */
6 shm_id = shmget(ipc_key, shm_size, IPC_CREAT|perm); /* get shm ID */
10 shm_ptr = shmat(shm_id, NULL, 0); /* map it into memory */
14 memset((void *)shm_ptr, fill, shm_size); /* fill segment */
17 /* Function ShmFind: Find a SysV shared memory segment */
18 void * ShmFind(key_t ipc_key, int shm_size)
21 int shm_id; /* ID of the SysV shared memory segment */
22 shm_id = shmget(ipc_key, shm_size, 0); /* find shared memory ID */
26 shm_ptr = shmat(shm_id, NULL, 0); /* map it into memory */
32 /* Function ShmRemove: Schedule removal for a SysV shared memory segment */
33 int ShmRemove(key_t ipc_key, void * shm_ptr)
35 int shm_id; /* ID of the SysV shared memory segment */
36 /* first detach segment */
37 if (shmdt(shm_ptr) < 0) {
40 /* schedule segment removal */
41 shm_id = shmget(ipc_key, 0, 0); /* find shared memory ID */
43 if (errno == EIDRM) return 0;
46 if (shmctl(shm_id, IPC_RMID, NULL) < 0) { /* ask for removal */
47 if (errno == EIDRM) return 0;