1/* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License version 2. 4 * 5 * This program is distributed in the hope that it will be useful, 6 * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 8 * GNU General Public License for more details. 9 * 10 * Test that the shm_unlink() function remove the name of the shared memory 11 * object named by the string pointed to by name. 12 */ 13 14 15#include <stdio.h> 16#include <sys/mman.h> 17#include <sys/stat.h> 18#include <unistd.h> 19#include <fcntl.h> 20#include <errno.h> 21#include "posixtest.h" 22 23#define SHM_NAME "posixtest_1-1" 24 25int main() { 26 int fd; 27 28 fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); 29 if(fd == -1) { 30 perror("An error occurs when calling shm_open()"); 31 return PTS_UNRESOLVED; 32 } 33 34 if(close(fd) != 0) { 35 perror("An error occurs when calling close()"); 36 shm_unlink(SHM_NAME); 37 return PTS_UNRESOLVED; 38 } 39 40 if(shm_unlink(SHM_NAME) != 0 ) { 41 perror("An error occurs when calling shm_unlink()"); 42 return PTS_UNRESOLVED; 43 } 44 45 fd = shm_open(SHM_NAME, O_RDONLY, 0); 46 47 if(fd == -1 && errno == ENOENT) { 48 printf("Test PASSED\n"); 49 return PTS_PASS; 50 } else if (fd == -1) { 51 perror("shm_open"); 52 return PTS_UNRESOLVED; 53 } 54 55 printf("The name of shared memory object was not removed.\n"); 56 shm_unlink(SHM_NAME); 57 return PTS_FAIL; 58 59} 60