Add POSIX test suite 1.5.2 (http://sourceforge.net/projects/posixtest/).
[dragonfly.git] / test / contrib / posixtestsuite-1.5.2 / conformance / interfaces / sem_open / 1-4.c
1 /*
2     Copyright (c) 2002-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  sem_open test case that attempts to open a new semaphoree, and then
11  try to un-lock it with sem_post.  Making sure the semaphore is not locked.
12  */
13
14 #include <sys/types.h>
15 #include <stdio.h>
16 #include <errno.h>
17 #include <unistd.h>
18 #include <semaphore.h>
19 #include <sys/stat.h>
20 #include <fcntl.h>
21 #include "posixtest.h"
22
23 #define TEST "1-4"
24 #define FUNCTION "sem_open"
25 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
26
27
28 int main()
29 {
30         sem_t   *mysemp;
31         char semname[20];
32
33         sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid());
34
35         mysemp = sem_open(semname, O_CREAT, 0777, 1);
36         if( mysemp == SEM_FAILED || mysemp == NULL ) {
37                 perror(ERROR_PREFIX "sem_open");
38                 return PTS_UNRESOLVED;
39         }
40
41
42         /* Checking if mysemp has a value returned. From sem_open */
43         if ( sem_post(mysemp) == 0 ) {
44                 puts("TEST PASSED");
45                 sem_close(mysemp);
46                 sem_unlink(semname);
47                 return PTS_PASS;
48         } else {
49                 puts("TEST FAILED");
50                 return PTS_FAIL;
51         }
52 }