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