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 sets errno = ENAMETOOLONG if the length 11 * of the name argument exceeds {PATH_MAX} (including the terminating null). 12 * 13 * The used name follow the scheme: 14 * aaaaaa/aaaaaa/aaaaaa/aaa ... 15 */ 16 17 #include <stdio.h> 18 #include <sys/mman.h> 19 #include <sys/stat.h> 20 #include <fcntl.h> 21 #include <errno.h> 22 #include <limits.h> 23 #include <unistd.h> 24 #include <stdlib.h> 25 #include "posixtest.h" 26 27 /* Ensure that each component length is short enough */ 28 #define COMPONENT_SIZE _POSIX_NAME_MAX 29 30 int main(void) 31 { 32 int result, i, path_max; 33 char *shm_name; 34 35 path_max = pathconf("/", _PC_PATH_MAX); 36 if (path_max == -1) { 37 perror("pathconf() failed"); 38 return PTS_UNRESOLVED; 39 } 40 shm_name = malloc(path_max + 1); 41 42 if (!shm_name) { 43 perror("malloc() failed"); 44 return PTS_UNRESOLVED; 45 } 46 47 for (i = 0; i < path_max; i++) 48 shm_name[i] = (i + 1) % COMPONENT_SIZE ? 'a' : '/'; 49 shm_name[path_max] = 0; 50 51 result = shm_unlink(shm_name); 52 53 if (result == -1 && errno == ENAMETOOLONG) { 54 printf("Test PASSED\n"); 55 return PTS_PASS; 56 } else if (result != -1) { 57 printf("FAILED: shm_unlink() succeeded.\n"); 58 return PTS_FAIL; 59 } 60 61 if (sysconf(_SC_VERSION) >= 200800L) { 62 printf("UNTESTED: shm_open() did not fail with ENAMETOLONG\n"); 63 return PTS_UNTESTED; 64 } 65 66 perror("FAILED: shm_unlink"); 67 return PTS_FAIL; 68 } 69