sem_init.c 276 B

123456789101112131415
  1. #include <semaphore.h>
  2. #include <limits.h>
  3. #include <errno.h>
  4. int sem_init(sem_t *sem, int pshared, unsigned value)
  5. {
  6. if (value > SEM_VALUE_MAX) {
  7. errno = EINVAL;
  8. return -1;
  9. }
  10. sem->__val[0] = value;
  11. sem->__val[1] = 0;
  12. sem->__val[2] = pshared ? 0 : 128;
  13. return 0;
  14. }