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 a pathname component is longer than {NAME_MAX} (not including the 12 * terminating null). 13 */ 14 15#include <stdio.h> 16#include <sys/mman.h> 17#include <errno.h> 18#include <limits.h> 19#include <unistd.h> 20#include <stdlib.h> 21#include "posixtest.h" 22 23int main() { 24 int result, i; 25 long name_max; 26 char *shm_name; 27 28 name_max = pathconf("/", _PC_NAME_MAX); 29 shm_name = malloc(name_max+3); 30 31 shm_name[0] = '/'; 32 for(i=1; i<name_max+2; i++) 33 shm_name[i] = 'a'; 34 shm_name[name_max+2] = 0; 35 36 result = shm_unlink(shm_name); 37 38 if(result == -1 && errno == ENAMETOOLONG) { 39 printf("Test PASSED\n"); 40 return PTS_PASS; 41 } else if(result != -1) { 42 printf("shm_unlink() success.\n"); 43 return PTS_FAIL; 44 } 45 46 perror("shm_unlink does not set the right errno"); 47 return PTS_FAIL; 48} 49