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 28int main() 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 41 queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); 42 if (queue != (mqd_t)-1) { 43 printf("mq_open() should have failed with queue name %s\n", 44 qname); 45 printf("Test FAILED\n"); 46 mq_close(queue); 47 mq_unlink(qname); 48 return PTS_FAIL; 49 } 50 51#ifdef DEBUG 52 printf("mq_open() failed as expected\n"); 53#endif 54 55 if (errno != ENAMETOOLONG) { 56 printf("errno != ENAMETOOLONG\n"); 57 printf("Test FAILED\n"); 58 return PTS_FAIL; 59 } 60 61#ifdef DEBUG 62 printf("errno == ENAMETOOLONG\n"); 63#endif 64 65 printf("Test PASSED\n"); 66 return PTS_PASS; 67} 68 69