#include #include #include #include #include int getShmid(int row, int col) { int shmid = shmget(ftok(KEYFILE, 'z'), row * col * sizeof(tile_t), IPC_CREAT | S_IRUSR | S_IWUSR); if (shmid == -1) { errExit("shmget", "getShmid"); } return shmid; } tile_t * shmServerAt(int shmid) { tile_t *result = (tile_t *)shmat(shmid, NULL, 0); if (result == SHMERR) { errExit("shmat", "shmServerAt"); } return result; } tile_t * shmClientAt(int shmid) { tile_t *result = (tile_t *)shmat(shmid, NULL, SHM_RDONLY); if (result == SHMERR) { errExit("shmat", "shmClientAt"); } return result; } void shmDt(void *shm_ptr) { if (shmdt(shm_ptr) == -1) { errExit("shmdt", "shmDt"); } } void shmServerRm(int shmid) { if (shmctl(shmid, IPC_RMID, NULL) == -1) { errExit("shmctl", "shmServerRm"); } }