RetroZilla/security/nss/lib/jar/jarint.c

53 lines
1.2 KiB
C
Raw Normal View History

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