michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Internal libjar routines. michael@0: */ michael@0: michael@0: #include "jar.h" michael@0: #include "jarint.h" michael@0: michael@0: /*----------------------------------------------------------------------- michael@0: * JAR_FOPEN_to_PR_Open michael@0: * Translate JAR_FOPEN arguments to PR_Open arguments michael@0: */ michael@0: PRFileDesc* michael@0: JAR_FOPEN_to_PR_Open(const char* name, const char *mode) michael@0: { michael@0: michael@0: PRIntn prflags=0, prmode=0; michael@0: michael@0: /* Get read/write flags */ michael@0: if (strchr(mode, 'r') && !strchr(mode, '+')) { michael@0: prflags |= PR_RDONLY; michael@0: } else if( (strchr(mode, 'w') || strchr(mode, 'a')) && michael@0: !strchr(mode,'+') ) { michael@0: prflags |= PR_WRONLY; michael@0: } else { michael@0: prflags |= PR_RDWR; michael@0: } michael@0: michael@0: /* Create a new file? */ michael@0: if (strchr(mode, 'w') || strchr(mode, 'a')) { michael@0: prflags |= PR_CREATE_FILE; michael@0: } michael@0: michael@0: /* Append? */ michael@0: if (strchr(mode, 'a')) { michael@0: prflags |= PR_APPEND; michael@0: } michael@0: michael@0: /* Truncate? */ michael@0: if (strchr(mode, 'w')) { michael@0: prflags |= PR_TRUNCATE; michael@0: } michael@0: michael@0: /* We can't do umask because it isn't XP. Choose some default michael@0: mode for created files */ michael@0: prmode = 0755; michael@0: michael@0: return PR_Open(name, prflags, prmode); michael@0: }