1 /* 2 * Copyright (c) 2003, Intel Corporation. All rights reserved. 3 * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 */ 8 9 /* 10 * Test that mq_open() fails with ENAMETOOLONG if the name parameter's 11 * length is greater than PATH_MAX. 12 */ 13 14 #include <stdio.h> 15 #include <mqueue.h> 16 #include <fcntl.h> 17 #include <sys/stat.h> 18 #include <sys/types.h> 19 #include <unistd.h> 20 #include <string.h> 21 #include <errno.h> 22 #include <limits.h> 23 #include "posixtest.h" 24 25 int main(void) 26 { 27 char qname[PATH_MAX * 2]; 28 mqd_t queue; 29 int i; 30 31 sprintf(qname, "/mq_open_27-1_%d", getpid()); 32 33 /* Ensures queue name will have > PATH_MAX chars */ 34 for (i = 0; i < PATH_MAX; i++) 35 strcat(qname, "0"); 36 37 queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); 38 if (queue != (mqd_t) - 1) { 39 printf("mq_open() should have failed with queue name %s\n", 40 qname); 41 printf("Test FAILED\n"); 42 mq_close(queue); 43 mq_unlink(qname); 44 return PTS_FAIL; 45 } 46 #ifdef DEBUG 47 printf("mq_open() failed as expected\n"); 48 #endif 49 50 if (errno != ENAMETOOLONG) { 51 printf("errno != ENAMETOOLONG\n"); 52 printf("Test FAILED\n"); 53 return PTS_FAIL; 54 } 55 #ifdef DEBUG 56 printf("errno == ENAMETOOLONG\n"); 57 #endif 58 59 printf("Test PASSED\n"); 60 return PTS_PASS; 61 } 62