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 30int main() { 31 int result, i, path_max; 32 char *shm_name; 33 34 path_max = pathconf("/", _PC_PATH_MAX); 35 if(path_max == -1) { 36 perror("An error occurs when calling pathconf()"); 37 return PTS_UNRESOLVED; 38 } 39 shm_name = malloc(path_max+1); 40 41 for(i=0; i<path_max; i++) 42 shm_name[i] = (i+1)%COMPONENT_SIZE ? 'a' : '/'; 43 shm_name[path_max+1] = 0; 44 45 result = shm_unlink(shm_name); 46 47 if(result == -1 && errno == ENAMETOOLONG) { 48 printf("Test PASSED\n"); 49 return PTS_PASS; 50 } else if(result != -1) { 51 printf("shm_unlink() success.\n"); 52 return PTS_FAIL; 53 } 54 55 perror("shm_unlink"); 56 return PTS_FAIL; 57} 58