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
| byte* SHM_init(mem_t* mem, size_t shm_size){
//Creation SHM
int i,j;
if((shmid = shmget((key_t)401 , shm_size , IPC_CREAT|0666)) == -1){
fprintf(stderr,"SHM_init : Erreur lors de la creation de SHM\n");
exit(-1);
}
//Attachement
byte* shm = (byte*)shmat(shmid , NULL , 0);
if(shm == (void*)(-1)){
fprintf(stderr,"SHM_init : Erreur lors de l'attachement\n");
exit(-1);
}
//Joueurs
(*shm) = (byte)mem->nbMaxJ; shm++;
(*shm) = mem->nbJoueurs; shm++;
for(i=0 ; i<(ceil((mem->nbMaxJ)/8)) ; i++){
(*shm) = mem->statutJoueurs[i];
shm++;
}
/* ... */
printf("Initialisation SHM terminee\n");
return shm;
} |
Partager