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/* sem_timedwait shall return zero if the calling process successfully
10 * performed the semaphore lock operation on the semaphore designated
11 * by sem.
12 */
13
14#define _XOPEN_SOURCE 600
15
16#include <stdio.h>
17#include <errno.h>
18#include <unistd.h>
19#include <semaphore.h>
20#include <sys/stat.h>
21#include <fcntl.h>
22#include <time.h>
23#include "posixtest.h"
24
25
26#define TEST "4-1"
27#define FUNCTION "sem_timedwait"
28#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
29
30
31
32int main() {
33	sem_t mysemp;
34	struct timespec ts;
35	int unresolved=0, sts;
36
37
38        if ( sem_init (&mysemp, 0, 1) == -1 ) {
39                perror(ERROR_PREFIX "sem_init");
40		unresolved=1;
41        }
42
43	ts.tv_sec=time(NULL)+1;
44        ts.tv_nsec=0;
45
46	/* Lock Semaphore */
47	sts = sem_timedwait(&mysemp, &ts);
48        if ( sts == -1 ) {
49		perror(ERROR_PREFIX "sem_timedwait");
50		unresolved=1;
51	}
52
53
54	/* unlock Semaphore */
55	if( sem_post(&mysemp) == -1 ) {
56		perror(ERROR_PREFIX "sem_post");
57		unresolved=1;
58	}
59
60	if (( sts == 0) && (unresolved == 0)) {
61		puts("TEST PASSED");
62		sem_destroy(&mysemp);
63		return PTS_PASS;
64	} else {
65		puts("TEST FAILED");
66		return PTS_FAIL;
67	}
68}
69