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/*
11   This test case checks for the existence of the semaphore and the creation
12   of the semaphore if it does not exist.
13 */
14
15#include <sys/types.h>
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 "posixtest.h"
23
24#define TEST "2-2"
25#define FUNCTION "sem_open"
26#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
27
28
29int main()
30{
31	sem_t   *mysemp;
32	char semname[50];
33
34	sprintf(semname, "/" FUNCTION "_" TEST "_%ld", (long)getpid());
35
36	mysemp = sem_open(semname, O_CREAT|O_EXCL, 0777, 1);
37
38
39	if ( mysemp  == SEM_FAILED || mysemp == NULL) {
40  		perror(ERROR_PREFIX "sem_open");
41		return PTS_UNRESOLVED;
42	}
43
44	if (errno != EEXIST )
45	{
46		puts("TEST PASSED");
47		sem_unlink(semname);
48		sem_close(mysemp);
49		return PTS_PASS;
50	}
51	else
52	{
53		puts("TEST FAILED");
54		return PTS_FAIL;
55	}
56}
57