forked from Mickyconca/TP1SO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsem_lib.c
35 lines (32 loc) · 839 Bytes
/
sem_lib.c
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
31
32
33
34
35
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "sem_lib.h"
t_sem createSem(char *name)
{
t_sem toReturn = {0};
strcpy(toReturn.name, name);
toReturn.access = sem_open(toReturn.name, O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, 0);
if (toReturn.access == SEM_FAILED)
{
HANDLE_ERROR("Error in sem_open");
}
return toReturn;
}
void closeSem(t_sem *sem)
{
if (sem_close(sem->access) == -1)
{
HANDLE_ERROR("Error in sem_close");
}
}
void eraseSem(t_sem *sem)
{
if (sem_close(sem->access) == -1)
{
HANDLE_ERROR("Error in sem_close");
}
if (sem_unlink(sem->name) == -1)
{
HANDLE_ERROR("Error in sem_unlink");
}
}