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 /* 10 * this test case verifies that the named semaphore has been removed after 11 * calling sem_unlink. 12 */ 13 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_unlink" 24 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 25 26 int main(void) 27 { 28 sem_t *mysemp; 29 char semname[28]; 30 31 sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); 32 33 /* Initial value of Semaphore is 1 */ 34 mysemp = sem_open(semname, O_CREAT, 0, 1); 35 if (mysemp == SEM_FAILED || mysemp == NULL) { 36 perror(ERROR_PREFIX "sem_open"); 37 return PTS_UNRESOLVED; 38 } 39 40 if (sem_unlink(semname) == 0) { 41 if ((sem_wait(mysemp)) == -1) { 42 puts("TEST FAILED: Couldn't remove named semaphore"); 43 return PTS_FAIL; 44 } else { 45 puts("TEST PASSED"); 46 sem_close(mysemp); 47 return PTS_PASS; 48 } 49 } 50 puts("TEST FAILED"); 51 return PTS_FAIL; 52 } 53