|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /* |
|
6 * Internal libjar routines. |
|
7 */ |
|
8 |
|
9 #include "jar.h" |
|
10 #include "jarint.h" |
|
11 |
|
12 /*----------------------------------------------------------------------- |
|
13 * JAR_FOPEN_to_PR_Open |
|
14 * Translate JAR_FOPEN arguments to PR_Open arguments |
|
15 */ |
|
16 PRFileDesc* |
|
17 JAR_FOPEN_to_PR_Open(const char* name, const char *mode) |
|
18 { |
|
19 |
|
20 PRIntn prflags=0, prmode=0; |
|
21 |
|
22 /* Get read/write flags */ |
|
23 if (strchr(mode, 'r') && !strchr(mode, '+')) { |
|
24 prflags |= PR_RDONLY; |
|
25 } else if( (strchr(mode, 'w') || strchr(mode, 'a')) && |
|
26 !strchr(mode,'+') ) { |
|
27 prflags |= PR_WRONLY; |
|
28 } else { |
|
29 prflags |= PR_RDWR; |
|
30 } |
|
31 |
|
32 /* Create a new file? */ |
|
33 if (strchr(mode, 'w') || strchr(mode, 'a')) { |
|
34 prflags |= PR_CREATE_FILE; |
|
35 } |
|
36 |
|
37 /* Append? */ |
|
38 if (strchr(mode, 'a')) { |
|
39 prflags |= PR_APPEND; |
|
40 } |
|
41 |
|
42 /* Truncate? */ |
|
43 if (strchr(mode, 'w')) { |
|
44 prflags |= PR_TRUNCATE; |
|
45 } |
|
46 |
|
47 /* We can't do umask because it isn't XP. Choose some default |
|
48 mode for created files */ |
|
49 prmode = 0755; |
|
50 |
|
51 return PR_Open(name, prflags, prmode); |
|
52 } |