rmdir.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. ** File: rmdir.c
  7. ** Description: Demonstrate bugzilla 80884.
  8. **
  9. ** after fix to unix_errors.c, message should report correct
  10. ** failure of PR_Rmdir().
  11. **
  12. **
  13. **
  14. */
  15. #include <prio.h>
  16. #include <stdio.h>
  17. #include <prerror.h>
  18. #include <prlog.h>
  19. #include "plgetopt.h"
  20. #define DIRNAME "xxxBug80884/"
  21. #define FILENAME "file80883"
  22. PRBool failed_already = PR_FALSE;
  23. PRBool debug_mode = PR_FALSE;
  24. PRLogModuleInfo *lm;
  25. /*
  26. ** Help() -- print Usage information
  27. */
  28. static void Help( void ) {
  29. fprintf(stderr, "template usage:\n"
  30. "\t-d debug mode\n"
  31. );
  32. } /* --- end Help() */
  33. int main(int argc, char **argv)
  34. {
  35. PLOptStatus os;
  36. PLOptState *opt = PL_CreateOptState(argc, argv, "dh");
  37. PRFileDesc* fd;
  38. PRErrorCode err;
  39. /* parse command line options */
  40. while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) {
  41. if (PL_OPT_BAD == os) {
  42. continue;
  43. }
  44. switch (opt->option) {
  45. case 'd': /* debug mode */
  46. debug_mode = PR_TRUE;
  47. break;
  48. case 'h':
  49. default:
  50. Help();
  51. return 2;
  52. }
  53. }
  54. PL_DestroyOptState(opt);
  55. lm = PR_NewLogModule( "testcase" );
  56. (void) PR_MkDir( DIRNAME, 0777);
  57. fd = PR_Open( DIRNAME FILENAME, PR_CREATE_FILE|PR_RDWR, 0666);
  58. if (fd == 0) {
  59. PRErrorCode err = PR_GetError();
  60. fprintf(stderr, "create file fails: %d: %s\n", err,
  61. PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
  62. failed_already = PR_TRUE;
  63. goto Finished;
  64. }
  65. PR_Close(fd);
  66. if (PR_RmDir( DIRNAME ) == PR_SUCCESS) {
  67. fprintf(stderr, "remove directory succeeds\n");
  68. failed_already = PR_TRUE;
  69. goto Finished;
  70. }
  71. err = PR_GetError();
  72. fprintf(stderr, "remove directory fails with: %d: %s\n", err,
  73. PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
  74. (void) PR_Delete( DIRNAME FILENAME);
  75. (void) PR_RmDir( DIRNAME );
  76. return 0;
  77. Finished:
  78. if ( debug_mode ) {
  79. printf("%s\n", ( failed_already ) ? "FAILED" : "PASS" );
  80. }
  81. return( (failed_already)? 1 : 0 );
  82. } /* --- end main() */
  83. /* --- end template.c */