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 = 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 <sys/stat.h> 18#include <fcntl.h> 19#include <errno.h> 20#include <unistd.h> 21#include <stdlib.h> 22#include "posixtest.h" 23 24int main(void) 25{ 26 int fd, i; 27 long name_max; 28 char *shm_name; 29 30 name_max = pathconf("/", _PC_NAME_MAX); 31 if (name_max == -1) { 32 perror("An error occurs when calling pathconf()"); 33 return PTS_UNRESOLVED; 34 } 35 shm_name = malloc(name_max + 3); 36 37 shm_name[0] = '/'; 38 for (i = 1; i < name_max + 2; i++) 39 shm_name[i] = 'a'; 40 shm_name[name_max + 2] = 0; 41 42 fd = shm_open(shm_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 43 44 if (fd == -1 && errno == ENAMETOOLONG) { 45 printf("Test PASSED\n"); 46 return PTS_PASS; 47 } else if (fd != -1) { 48 printf("FAILED: shm_open() succeeded\n"); 49 shm_unlink(shm_name); 50 return PTS_FAIL; 51 } 52 53 if (sysconf(_SC_VERSION) >= 200800L) { 54 printf("UNTESTED: shm_open() did not fail with ENAMETOLONG\n"); 55 return PTS_UNTESTED; 56 } 57 58 perror("FAILED: shm_open"); 59 return PTS_FAIL; 60} 61