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 greater than or equal to
12  * 1000 million.  Should return ERROR (EINVAL).
13 */
14 
15 
16 #define _XOPEN_SOURCE 600
17 
18 #include <stdio.h>
19 #include <errno.h>
20 #include <unistd.h>
21 #include <semaphore.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <time.h>
25 #include "posixtest.h"
26 
27 
28 #define TEST "5-1"
29 #define FUNCTION "sem_timedwait"
30 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
31 
32 #define NANOSEC 1000000000
33 
main()34 int main() {
35 	sem_t mysemp;
36 	struct timespec ts;
37 	int sts;
38 
39         if ( sem_init (&mysemp, 0, 0) == -1 ) {
40                 perror(ERROR_PREFIX "sem_init");
41                 return PTS_UNRESOLVED;
42         }
43 	ts.tv_sec=time(NULL);
44         ts.tv_nsec= NANOSEC;
45 
46 	sts = sem_timedwait(&mysemp, &ts);
47 
48 	if(( errno == EINVAL) && ( sts == -1)) {
49 		puts("TEST PASSED");
50 		sem_destroy(&mysemp);
51 		return PTS_PASS;
52 	} else {
53 		puts("TEST FAILED");
54 		return PTS_FAIL;
55 	}
56 }
57