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 shared memory object has a size of zero when created. 11 * 12 * The test use fstat to get the size of shared memory object. 13 */ 14 15#include <sys/mman.h> 16#include <sys/stat.h> 17#include <fcntl.h> 18#include <stdio.h> 19#include <errno.h> 20#include <unistd.h> 21#include "posixtest.h" 22 23#define SHM_NAME "posixtest_21-1" 24 25int main(){ 26 int fd, result; 27 struct stat stat_buf; 28 29 result = shm_unlink(SHM_NAME); 30 if(result != 0 && errno != ENOENT) { 31 /* The shared memory object exist and shm_unlink can not 32 remove it. */ 33 perror("An error occurs when calling shm_unlink()"); 34 return PTS_UNRESOLVED; 35 } 36 37 fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); 38 if(fd == -1) { 39 perror("An error occurs when calling shm_open()"); 40 return PTS_UNRESOLVED; 41 } 42 43 result = fstat(fd, &stat_buf); 44 if(result != 0) { 45 perror("An error occurs when calling fstat()"); 46 shm_unlink(SHM_NAME); 47 return PTS_UNRESOLVED; 48 } 49 50 shm_unlink(SHM_NAME); 51 52 if(stat_buf.st_size == 0) { 53 printf("Test PASSED\n"); 54 return PTS_PASS; 55 } 56 printf("The shared memory object has not a size of zero.\n"); 57 return PTS_FAIL; 58} 59 60