1/* 2 Copyright (c) 2002, 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_close will have no effect on the state of the semaphore if 11 sem_unlink has been unsuccessful. 12*/ 13 14 15 16#include <sys/types.h> 17#include <stdio.h> 18#include <errno.h> 19#include <unistd.h> 20#include <semaphore.h> 21#include <sys/stat.h> 22#include <fcntl.h> 23#include "posixtest.h" 24 25#define TEST "3-1" 26#define FUNCTION "sem_close" 27#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 28 29 30int main() 31{ 32 sem_t *mysemp; 33 char semname[50]; 34 35 sprintf(semname, "/" FUNCTION "_" TEST "_%ld", (long)getpid()); 36 37 mysemp = sem_open(semname, O_CREAT, 0444, 1) ; 38 if (mysemp == SEM_FAILED) { 39 perror(ERROR_PREFIX "sem_open"); 40 return PTS_UNRESOLVED; 41 } 42 43 if ((sem_unlink(semname)) == 0) { 44 if ( sem_close(mysemp) == -1) { 45 perror(ERROR_PREFIX "sem_close"); 46 return PTS_UNRESOLVED; 47 } 48 puts("TEST PASSED"); 49 return PTS_PASS; 50 } else { 51 52 puts("TEST FAILED"); 53 return PTS_FAIL; 54 } 55} 56 57 58 59