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_open() function sets errno = EINVAL if the shm_open() 11 * operation is not supported for the given name. 12 * 13 * The supported names are implementation-defined, so the test is done for 14 * several differents names. The test pass for a given name if shm_open make no 15 * error or set errno to EINVAL. 16 */ 17 18#include <stdio.h> 19#include <sys/mman.h> 20#include <sys/stat.h> 21#include <fcntl.h> 22#include <errno.h> 23#include "posixtest.h" 24 25char *shm_name[] = { 26 /* char which are in portable character set but not in portable 27 filename character set */ 28 "$#\n@\t\a,~}", 29 /* char which are not in portable character set (accentuated char and c 30 cedilla) */ 31 "������", 32 /* some file or directory which should exist */ 33 "..", 34 "/", 35 "//", 36 "/abc", 37 NULL 38}; 39 40int main(void) 41{ 42 int fd, i = 0, result = PTS_PASS; 43 44 while (shm_name[i]) { 45 fflush(stderr); 46 printf("Name: '%s'\n", shm_name[i]); 47 fflush(stdout); 48 49 fd = shm_open(shm_name[i], O_RDWR | O_CREAT, 0); 50 51 if (fd == -1 && errno == EINVAL) { 52 printf(" OK: errno == EINVAL\n"); 53 } else if (fd != -1) { 54 printf(" OK: open with success.\n"); 55 } else { 56 perror(" Unexpected error"); 57 result = PTS_FAIL; 58 } 59 60 shm_unlink(shm_name[i]); 61 62 i++; 63 } 64 65 if (result == PTS_PASS) 66 printf("Test PASSED\n"); 67 else 68 printf("Test FAILED\n"); 69 return result; 70} 71