op_2long.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. ** Name: op_2long.c
  8. **
  9. ** Description: Test Program to verify the PR_NAME_TOO_LONG_ERROR
  10. **
  11. ** Modification History:
  12. ** 03-June-97 AGarcia- Initial version
  13. ***********************************************************************/
  14. /***********************************************************************
  15. ** Includes
  16. ***********************************************************************/
  17. /* Used to get the command line option */
  18. #include "prinit.h"
  19. #include "prmem.h"
  20. #include "prio.h"
  21. #include "prerror.h"
  22. #include <stdio.h>
  23. #include "plerror.h"
  24. #include "plgetopt.h"
  25. static PRFileDesc *t1;
  26. PRIntn error_code;
  27. /*
  28. * should exceed any system's maximum file name length
  29. * Note: was set at 4096. This is legal on some unix (Linux 2.1+) platforms.
  30. *
  31. */
  32. #define TOO_LONG 5000
  33. int main(int argc, char **argv)
  34. {
  35. char nameTooLong[TOO_LONG];
  36. int i;
  37. /* Generate a really long pathname */
  38. for (i = 0; i < TOO_LONG - 1; i++) {
  39. if (i % 10 == 0) {
  40. nameTooLong[i] = '/';
  41. } else {
  42. nameTooLong[i] = 'a';
  43. }
  44. }
  45. nameTooLong[TOO_LONG - 1] = 0;
  46. PR_STDIO_INIT();
  47. t1 = PR_Open(nameTooLong, PR_RDWR, 0666);
  48. if (t1 == NULL) {
  49. if (PR_GetError() == PR_NAME_TOO_LONG_ERROR) {
  50. PL_PrintError("error code is");
  51. printf ("PASS\n");
  52. return 0;
  53. }
  54. else {
  55. PL_PrintError("error code is");
  56. printf ("FAIL\n");
  57. return 1;
  58. }
  59. }
  60. else {
  61. printf ("Test passed\n");
  62. return 0;
  63. }
  64. }