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 a component of the 11 * name is greater than NAME_MAX. 12 * 13 * Since a component == the full name, this test will be identical to 14 * 27-1.c for NAME_MAX. 15 */ 16 17 #include <stdio.h> 18 #include <mqueue.h> 19 #include <fcntl.h> 20 #include <sys/stat.h> 21 #include <sys/types.h> 22 #include <unistd.h> 23 #include <string.h> 24 #include <errno.h> 25 #include <limits.h> 26 #include "posixtest.h" 27 28 int main(void) 29 { 30 char qname[NAME_MAX * 2]; 31 mqd_t queue; 32 int i; 33 34 sprintf(qname, "/mq_open_27-1_%d", getpid()); 35 36 /* Ensures queue name will have > NAME_MAX chars */ 37 for (i = 0; i < NAME_MAX; i++) 38 strcat(qname, "0"); 39 40 queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); 41 if (queue != (mqd_t) - 1) { 42 printf("mq_open() should have failed with queue name %s\n", 43 qname); 44 printf("Test FAILED\n"); 45 mq_close(queue); 46 mq_unlink(qname); 47 return PTS_FAIL; 48 } 49 #ifdef DEBUG 50 printf("mq_open() failed as expected\n"); 51 #endif 52 53 if (errno != ENAMETOOLONG) { 54 printf("errno != ENAMETOOLONG\n"); 55 printf("Test FAILED\n"); 56 return PTS_FAIL; 57 } 58 #ifdef DEBUG 59 printf("errno == ENAMETOOLONG\n"); 60 #endif 61 62 printf("Test PASSED\n"); 63 return PTS_PASS; 64 } 65