Commit 0c024698 authored by Ivaylo Ivanov's avatar Ivaylo Ivanov

Move the truncation outside of the open function

parent 2c4471a7
......@@ -22,12 +22,14 @@ int create_shmfd(char *shm_name) {
return shmfd;
}
void* open_shm(int shmfd, size_t shm_size) {
void truncate_shm(int shmfd, size_t shm_size) {
if(ftruncate(shmfd, shm_size) < 0) {
fprintf(stderr, "ERROR: Failed truncating shared memory object\n");
exit(EXIT_FAILURE);
}
}
void* open_shm(int shmfd, size_t shm_size) {
void* shm;
shm = mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
......
......@@ -33,6 +33,7 @@ int main(int argc, char *argv[]) {
/// Open shared memory objects
int buffer_shmfd = create_shmfd(BUFFER_SHM_NAME);
truncate_shm(buffer_shmfd, BUFF_SIZE);
circ_buffer = (buffer_t *)open_shm(buffer_shmfd, sizeof(buffer_t));
/// Open semaphores
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment