Home | History | Annotate | Download | only in sem_timedwait
      1 /*
      2  * Copyright (c) 2003, Intel Corporation. All rights reserved.
      3  * Created by:  majid.awad REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7  */
      8 
      9 /*
     10  * The process would be blocked, and the timeout parameter is
     11  * secified in nanoseconds field value less than zero.  Should
     12  * return ERROR (EINVAL).
     13  */
     14 
     15 #define _XOPEN_SOURCE 600
     16 
     17 #include <stdio.h>
     18 #include <errno.h>
     19 #include <unistd.h>
     20 #include <semaphore.h>
     21 #include <sys/stat.h>
     22 #include <fcntl.h>
     23 #include <time.h>
     24 #include "posixtest.h"
     25 
     26 #define TEST "6-1"
     27 #define FUNCTION "sem_timedwait"
     28 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
     29 
     30 int main(void)
     31 {
     32 	sem_t mysemp;
     33 	struct timespec ts;
     34 	int sts;
     35 
     36 	if (sem_init(&mysemp, 0, 0) == -1) {
     37 		perror(ERROR_PREFIX "sem_init");
     38 		return PTS_UNRESOLVED;
     39 	}
     40 	ts.tv_sec = time(NULL);
     41 	ts.tv_nsec = -3;
     42 
     43 	sts = sem_timedwait(&mysemp, &ts);
     44 
     45 	if (errno == EINVAL && sts == -1) {
     46 		puts("TEST PASSED");
     47 		sem_destroy(&mysemp);
     48 		return PTS_PASS;
     49 	} else {
     50 		puts("TEST FAILED");
     51 		return PTS_FAIL;
     52 	}
     53 }
     54