1/* Copyright (c) 2002, Intel Corporation. All rights reserved. 2 Created by: majid.awad REMOVE-THIS AT intel DOT com 3 This file is licensed under the GPL license. For the full content 4 of this license, see the COPYING file at the top level of this 5 source tree. 6 */ 7 8/* 9 This case verifies that sem_close deallocate resources, and then the 10 semaphore is available for reuse. 11 */ 12 13#include <sys/types.h> 14#include <stdio.h> 15#include <errno.h> 16#include <unistd.h> 17#include <semaphore.h> 18#include <sys/stat.h> 19#include <fcntl.h> 20#include "posixtest.h" 21 22#define TEST "2-1" 23#define FUNCTION "sem_close" 24#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 25 26 27 28int main() 29{ 30 sem_t *mysemp; 31 char semname[50]; 32 33 sprintf(semname, "/" FUNCTION "_" TEST "_%ld", (long)getpid()); 34 35 mysemp = sem_open(semname, O_CREAT, 0777, 1); 36 37 if (mysemp == SEM_FAILED ) { 38 perror(ERROR_PREFIX "sem_open"); 39 return PTS_UNRESOLVED; 40 } 41 42 /* Deallocate mysemp */ 43 if ((sem_close(mysemp)) == -1) { 44 return PTS_UNRESOLVED; 45 } 46 47 /* Make mysemp available for reuse */ 48 mysemp = sem_open(semname, O_CREAT, 0777, 1); 49 50 if (mysemp == SEM_FAILED ) { 51 perror(ERROR_PREFIX "sem_open"); 52 return PTS_UNRESOLVED; 53 } 54 55 56 if ((sem_close(mysemp)) == 0) { 57 puts("TEST PASSED"); 58 sem_unlink(semname); 59 return PTS_PASS; 60 } else { 61 puts("TEST FAILED"); 62 return PTS_FAIL; 63 } 64} 65 66