l3.libnazgul/src/poolDataTabCreate.c
2020-03-03 23:46:32 +01:00

42 lines
974 B
C

#include "libnazgul.h"
#include "ids.h"
void * msgPoolDataTabCreate(msgSpace * space){
int poolDataFd; // shm file descriptor
msgPoolData * poolDataTabAddr;
poolDataFd=shm_open(
space->poolDataTabId,
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
MSGSPACE_DEFAULT_MODE
);
if (poolDataFd == -1 ) {
NZG_ERROR("shm_open :create",space->poolDataTabId);
goto ERROR;
}
/* allocation de la bonne zone mémoire pour le poolData */
if (ftruncate(poolDataFd, (space->poolNb)*sizeof(msgPoolData)) == -1){
NZG_ERROR("ftruncate",space->poolDataTabId);
goto ERROR;
}
close(poolDataFd);
poolDataTabAddr = msgPoolDataTabOpen(space);
if (poolDataTabAddr == NULL){
NZG_ERROR("msgPoolDataTabOpen : create",space->poolDataTabId);
goto ERROR;
}
/*mmap( 0, sizeof( *mSAddr ),
PROT_READ | PROT_WRITE,
MAP_SHARED, mSFd, 0 );
if( poolDataAddr == MAP_FAILED ) {
NZG_ERROR("mmap",poolDataTabId);
goto ERROR;
}*/
return poolDataTabAddr;
ERROR:
return NULL;
}