Commit b5f1bbd1 authored by Franksen, Benjamin's avatar Franksen, Benjamin
Browse files

psem: in sem_open, regard 0 /and/ -1 as failure; and then print the errno


VxWorks and RTEMS-4.9 return -1 on error, while Linux returns SEM_FAILED
which is NULL.
parent f01adedd
......@@ -394,11 +394,15 @@ int psem_named_create(char *name, int initial_state)
sem= (sem_open(name, O_CREAT | O_EXCL, 0,
initial_state ? 0 : 1));
if (-1==(long)sem)
if ((sem_t*)(-1)==sem || (sem_t*)(0)==sem)
{ if (errno==EEXIST)
/* if the semaphore already existed, 1 is returned */
return(1);
return(-1);
else
{
printf("psem_named_create: sem_open failed: %s\n", strerror(errno));
return(-1);
}
};
if (0!=sem_close(sem))
return(-1);
......@@ -429,9 +433,15 @@ boolean psem_named_open(char *name, psem_named *sem)
*sem= (psem_named)mq;
return(TRUE);
#else
if (-1==((ptrdiff_t)(*sem= (sem_open(name, 0, 0, 0)))))
return(FALSE);
return(TRUE);
*sem= (sem_open(name, 0, 0, 0));
if ((sem_t*)(-1)==*sem || (sem_t*)(0)==*sem)
{
printf("psem_named_create: sem_open failed: %s\n", strerror(errno));
return FALSE;
}
else
return TRUE;
#endif
}
......
Supports Markdown
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