Przeglądaj źródła

Ajout gestion erreur generation clef

Loquicom 6 lat temu
rodzic
commit
c4844b1ccc
1 zmienionych plików z 8 dodań i 0 usunięć
  1. 8 0
      sem.c

+ 8 - 0
sem.c

@@ -30,6 +30,10 @@ boolean create_sem(semaphore* sem, int code, int nb, int* iniVal) {
     extern int errno;
     /* Création du tableau */
     key_t key = ftok(IPCKEYPATH, code);
+    if(key == ERR){
+        addperror("Impossible de générer la clef");
+        return false;
+    }
     id = semget(key, nb, S_IRUSR | S_IWUSR | IPC_CREAT | IPC_EXCL);
     if (id == ERR) {
         /* Si le tableau existe deja */
@@ -54,6 +58,10 @@ boolean get_sem(semaphore* sem, int code) {
     struct semid_ds sem_buf;
     /* Création du tableau */
     key_t key = ftok(IPCKEYPATH, code);
+    if(key == ERR){
+        addperror("Impossible de générer la clef");
+        return false;
+    }
     id = semget(key, 0, S_IRUSR | S_IWUSR);
     if (id == ERR) {
         /* Sinon erreur */