Debian Codegraph @

nsprpub/pr/tests/rmdir.c

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