op_2long.c (1783B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /*********************************************************************** 7 ** 8 ** Name: op_2long.c 9 ** 10 ** Description: Test Program to verify the PR_NAME_TOO_LONG_ERROR 11 ** 12 ** Modification History: 13 ** 03-June-97 AGarcia- Initial version 14 ***********************************************************************/ 15 16 /*********************************************************************** 17 ** Includes 18 ***********************************************************************/ 19 /* Used to get the command line option */ 20 #include "prinit.h" 21 #include "prmem.h" 22 #include "prio.h" 23 #include "prerror.h" 24 #include <stdio.h> 25 #include "plerror.h" 26 #include "plgetopt.h" 27 28 static PRFileDesc* t1; 29 PRIntn error_code; 30 31 /* 32 * should exceed any system's maximum file name length 33 * Note: was set at 4096. This is legal on some unix (Linux 2.1+) platforms. 34 * 35 */ 36 #define TOO_LONG 5000 37 38 int main(int argc, char** argv) { 39 char nameTooLong[TOO_LONG]; 40 int i; 41 42 /* Generate a really long pathname */ 43 for (i = 0; i < TOO_LONG - 1; i++) { 44 if (i % 10 == 0) { 45 nameTooLong[i] = '/'; 46 } else { 47 nameTooLong[i] = 'a'; 48 } 49 } 50 nameTooLong[TOO_LONG - 1] = 0; 51 52 t1 = PR_Open(nameTooLong, PR_RDWR, 0666); 53 if (t1 == NULL) { 54 if (PR_GetError() == PR_NAME_TOO_LONG_ERROR) { 55 PL_PrintError("error code is"); 56 printf("PASS\n"); 57 return 0; 58 } else { 59 PL_PrintError("error code is"); 60 printf("FAIL\n"); 61 return 1; 62 } 63 } 64 65 else { 66 printf("Test passed\n"); 67 return 0; 68 } 69 }