本文整理汇总了C++中PR_Open函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_Open函数的具体用法?C++ PR_Open怎么用?C++ PR_Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_Open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NSFC_PR_Open
NSFC_PR_Open(const char *name,
PRIntn flags,
PRIntn mode)
{
PRFileDesc *fd;
#ifdef ESTALE
// Retry PR_Open() up to NSFC_ESTALE_RETRIES times if it returns ESTALE.
// Bug 545152
int retries = NSFC_ESTALE_RETRIES;
do {
fd = PR_Open(name, flags, mode);
} while (!fd && PR_GetOSError() == ESTALE && retries--);
#else
fd = PR_Open(name, flags, mode);
#endif
#ifdef XP_WIN32
/* Work-around for NSPR error mapping deficiency */
if ((fd == NULL) && (PR_GetError() == PR_UNKNOWN_ERROR)
&& (PR_GetOSError() == ERROR_SHARING_VIOLATION))
PR_SetError(PR_FILE_IS_BUSY_ERROR, ERROR_SHARING_VIOLATION);
#endif
return fd;
}
示例2: ParseData
nsresult ParseData(char* anInputStream,char* anOutputStream) {
NS_ENSURE_ARG_POINTER(anInputStream);
NS_ENSURE_ARG_POINTER(anOutputStream);
nsresult result = NS_OK;
// Create a parser
nsCOMPtr<nsIParser> parser(do_CreateInstance(kParserCID, &result));
if (NS_FAILED(result)) {
printf("\nUnable to create a parser\n");
return result;
}
// Create a sink
nsCOMPtr<nsILoggingSink> sink(do_CreateInstance(kLoggingSinkCID, &result));
if (NS_FAILED(result)) {
printf("\nUnable to create a sink\n");
return result;
}
PRFileDesc* in = PR_Open(anInputStream, PR_RDONLY, 0777);
if (!in) {
printf("\nUnable to open input file - %s\n", anInputStream);
return result;
}
PRFileDesc* out = PR_Open(anOutputStream,
PR_CREATE_FILE|PR_TRUNCATE|PR_RDWR, 0777);
if (!out) {
printf("\nUnable to open output file - %s\n", anOutputStream);
return result;
}
nsString stream;
char buffer[1024] = {0}; // XXX Yikes!
bool done = false;
PRInt32 length = 0;
while(!done) {
length = PR_Read(in, buffer, sizeof(buffer));
if (length != 0) {
stream.Append(NS_ConvertUTF8toUTF16(buffer, length));
}
else {
done=true;
}
}
sink->SetOutputStream(out);
parser->SetContentSink(sink);
result = parser->Parse(stream, 0, NS_LITERAL_CSTRING("text/html"), true);
PR_Close(in);
PR_Close(out);
return result;
}
示例3: ReadBuf
int
ReadBuf(char *inFile, SECItem *item)
{
int len;
int ret;
PRFileDesc* fd = PR_Open(inFile, PR_RDONLY, 0);
if (NULL == fd) {
SECU_PrintError("symkeyutil", "PR_Open failed");
return -1;
}
len = GetLen(fd);
if (len < 0) {
SECU_PrintError("symkeyutil", "PR_GetOpenFileInfo failed");
return -1;
}
item->data = (unsigned char *)PORT_Alloc(len);
if (item->data == NULL) {
fprintf(stderr,"Failed to allocate %d to read file %s\n",len,inFile);
return -1;
}
ret = PR_Read(fd,item->data,item->len);
if (ret < 0) {
SECU_PrintError("symkeyutil", "PR_Read failed");
PORT_Free(item->data);
item->data = NULL;
return -1;
}
PR_Close(fd);
item->len = len;
return 0;
}
示例4: GenerateRandomBytes
static
nsresult
GenerateRandomBytes(uint32_t aSize,
uint8_t* _buffer)
{
// On Windows, we'll use its built-in cryptographic API.
#if defined(XP_WIN)
HCRYPTPROV cryptoProvider;
BOOL rc = CryptAcquireContext(&cryptoProvider, 0, 0, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT);
if (rc) {
rc = CryptGenRandom(cryptoProvider, aSize, _buffer);
(void)CryptReleaseContext(cryptoProvider, 0);
}
return rc ? NS_OK : NS_ERROR_FAILURE;
// On Unix, we'll just read in from /dev/urandom.
#elif defined(XP_UNIX)
NS_ENSURE_ARG_MAX(aSize, INT32_MAX);
PRFileDesc* urandom = PR_Open("/dev/urandom", PR_RDONLY, 0);
nsresult rv = NS_ERROR_FAILURE;
if (urandom) {
int32_t bytesRead = PR_Read(urandom, _buffer, aSize);
if (bytesRead == static_cast<int32_t>(aSize)) {
rv = NS_OK;
}
(void)PR_Close(urandom);
}
return rv;
#endif
}
示例5: CheckFileContents
// Returns true if the contents of |file| match |contents|.
static PRBool CheckFileContents(nsILocalFile *file, const char *contents)
{
nsCString nativePath;
file->GetNativePath(nativePath);
// Now read in the file contents and compare to the expected output
PRFileInfo info;
ASSERT_TRUE_RET(PR_GetFileInfo(nativePath.get(), &info) == PR_SUCCESS,
PR_FALSE);
char *buf = new char[info.size + 1];
ASSERT_TRUE_RET(buf, PR_FALSE);
PRFileDesc *fd = PR_Open(nativePath.get(), PR_RDONLY, 0);
ASSERT_TRUE_RET(fd, PR_FALSE);
ASSERT_TRUE_RET(PR_Read(fd, buf, info.size) == info.size, PR_FALSE);
PR_Close(fd);
buf[info.size] = '\0';
// Leave the file in place if the test failed
ASSERT_TRUE_RET(!strcmp(buf, contents), PR_FALSE);
PR_Delete(nativePath.get());
delete[] buf;
return PR_TRUE;
}
示例6: PR_Open
am_status_t Properties::store(const std::string& fileName) const
{
am_status_t status = AM_SUCCESS;
PRFileDesc *propFile;
propFile = PR_Open(fileName.c_str(),
PR_WRONLY|PR_CREATE_FILE|PR_TRUNCATE, 0644);
if (NULL != propFile) {
PRUint32 rc = 0;
for (const_iterator iter = begin(); iter != end(); ++iter) {
rc = PR_fprintf(propFile, "%s=%s\n", iter->first.c_str(),
iter->second.c_str());
if (static_cast<PRUint32>(-1) == rc) {
break;
}
}
if (PR_SUCCESS != PR_Close(propFile) ||
static_cast<PRUint32>(-1) == rc) {
status = AM_NSPR_ERROR;
}
} else {
status = AM_NSPR_ERROR;
}
return status;
}
示例7: MOZ_ASSERT
nsresult
AutoMemMap::init(const char* filePath, int flags, int mode, PRFileMapProtect prot)
{
MOZ_ASSERT(!fd);
MOZ_ASSERT(!fileMap);
MOZ_ASSERT(!addr);
if (PR_GetFileInfo64(filePath, &fileInfo) != PR_SUCCESS)
return NS_ERROR_FILE_NOT_FOUND;
// Check if the file is too big to memmap.
if (fileInfo.size > int64_t(UINT32_MAX))
return NS_ERROR_INVALID_ARG;
auto length = uint32_t(fileInfo.size);
fd = PR_Open(filePath, flags, flags);
if (!fd)
return NS_ERROR_UNEXPECTED;
fileMap = PR_CreateFileMap(fd, fileInfo.size, prot);
if (!fileMap)
return NS_ERROR_UNEXPECTED;
addr = PR_MemMap(fileMap, 0, length);
if (!addr)
return NS_ERROR_UNEXPECTED;
return NS_OK;
}
示例8: PR_PUBLIC_API
/**
* ZIP_OpenArchive
*
* opens the named zip/jar archive and returns a handle that
* represents the archive in other ZIP_ calls.
*
* @param zipname archive filename
* @param hZip receives handle if archive opened OK
* @return status code
*/
PR_PUBLIC_API(PRInt32) ZIP_OpenArchive(const char * zipname, void** hZip)
{
PRInt32 status;
/*--- error check args ---*/
if (hZip == 0)
return ZIP_ERR_PARAM;
/*--- NULL output to prevent use by bozos who don't check errors ---*/
*hZip = 0;
/*--- create and open the archive ---*/
nsZipArchive* zip = new nsZipArchive();
if (zip == 0)
return ZIP_ERR_MEMORY;
PRFileDesc * fd = PR_Open(zipname, PR_RDONLY, 0400);
if (!fd) {
delete zip;
return ZIP_ERR_DISK;
}
status = zip->OpenArchive(fd);
if (status == ZIP_OK)
*hZip = static_cast<void*>(zip);
else {
delete zip;
PR_Close(fd);
}
return status;
}
示例9: RNG_FileForRNG
void RNG_FileForRNG(const char *filename)
{
PRFileDesc * file;
int nBytes;
PRFileInfo infoBuf;
unsigned char buffer[1024];
if (PR_GetFileInfo(filename, &infoBuf) != PR_SUCCESS)
return;
RNG_RandomUpdate((unsigned char*)&infoBuf, sizeof(infoBuf));
file = PR_Open(filename, PR_RDONLY, 0);
if (file != NULL) {
for (;;) {
PRInt32 bytes = PR_Read(file, buffer, sizeof buffer);
if (bytes <= 0)
break;
RNG_RandomUpdate(buffer, bytes);
totalFileBytes += bytes;
if (totalFileBytes > maxFileBytes)
break;
}
PR_Close(file);
}
nBytes = RNG_GetNoise(buffer, 20); // get up to 20 bytes
RNG_RandomUpdate(buffer, nBytes);
}
示例10: db_put_dn
void
db_put_dn(char *data_dn)
{
int ret;
char *db_path = DATABASE;
char *db_path_bak = DATABASE_BACK;
PRFileInfo64 info;
PRFileDesc *prfd;
PRInt32 data_sz;
char *data_dnp = NULL;
if(db_lock == NULL){
db_lock = PR_NewLock();
}
PR_Lock(db_lock);
/* if db_path is a directory, rename it */
ret = PR_GetFileInfo64(db_path, &info);
if (PR_SUCCESS == ret) {
if (PR_FILE_DIRECTORY == info.type) { /* directory */
ret = PR_GetFileInfo64(db_path_bak, &info);
if (PR_SUCCESS == ret) {
if (PR_FILE_DIRECTORY != info.type) { /* not a directory */
PR_Delete(db_path_bak);
}
}
PR_Rename(db_path, db_path_bak);
}
}
/* open a file */
if ((prfd = PR_Open(db_path, PR_RDWR | PR_CREATE_FILE | PR_APPEND, 0600)) == NULL ) {
slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME,
"db: Could not open file \"%s\" for read/write; %d (%s)\n",
db_path, PR_GetError(), slapd_pr_strerror(PR_GetError()));
return;
}
data_dnp = slapi_ch_smprintf("%s\n", data_dn);
data_sz = (PRInt32)strlen(data_dnp);
ret = PR_Write(prfd, data_dnp, data_sz);
if (ret == data_sz) {
slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME,
"db: %s: key stored.\n", data_dn);
ret = 0;
} else {
slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME,
"db: Failed to store key \"%s\"; %d (%s)\n",
data_dn, PR_GetError(), slapd_pr_strerror(PR_GetError()));
ret = 1;
}
if(ret) {
slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME,
"db: Error detected in db_put_dn \n");
}
slapi_ch_free_string(&data_dnp);
PR_Close(prfd);
PR_Unlock(db_lock);
return;
}
示例11: find_certificate
CERTCertificate*
find_certificate(CERTCertDBHandle *handle, const char *name, PRBool ascii)
{
CERTCertificate *cert = NULL;
SECItem der;
PRFileDesc *certFile;
if (handle == NULL || name == NULL)
return NULL;
if (ascii == PR_FALSE) {
/* by default need to check if there is cert nick is given */
cert = CERT_FindCertByNicknameOrEmailAddr (handle, (char *) name);
if (cert != NULL)
return cert;
}
certFile = PR_Open(name, PR_RDONLY, 0);
if (certFile == NULL) {
return NULL;
}
if (SECU_ReadDERFromFile(&der, certFile, ascii, PR_FALSE) == SECSuccess) {
cert = CERT_DecodeCertFromPackage((char*)der.data, der.len);
SECITEM_FreeItem(&der, PR_FALSE);
}
PR_Close(certFile);
return cert;
}
示例12: dumpCertChain
void
dumpCertChain(CERTCertificate *cert, SECCertUsage usage)
{
CERTCertificateList *certList;
unsigned int count = 0;
certList = CERT_CertChainFromCert(cert, usage, PR_TRUE);
if (certList == NULL) {
errWarn("CERT_CertChainFromCert");
return;
}
for(count = 0; count < (unsigned int)certList->len; count++) {
char certFileName[16];
PRFileDesc *cfd;
PR_snprintf(certFileName, sizeof certFileName, "cert.%03d",
count);
cfd = PR_Open(certFileName, PR_WRONLY|PR_CREATE_FILE|PR_TRUNCATE,
0664);
if (!cfd) {
PR_fprintf(PR_STDOUT,
"Error: couldn't save cert der in file '%s'\n",
certFileName);
} else {
PR_Write(cfd, certList->certs[count].data, certList->certs[count].len);
PR_Close(cfd);
PR_fprintf(PR_STDOUT, "Cert file %s was created.\n", certFileName);
}
}
CERT_DestroyCertificateList(certList);
}
示例13: InitializeRecording
static PRFileDesc * InitializeRecording( void )
{
char *logFileName;
PRFileDesc *logFile;
/* Self initialize, if necessary */
if ( traceLock == NULL )
_PR_InitializeTrace();
PR_LOG( lm, PR_LOG_DEBUG,
("PR_RecordTraceEntries: begins"));
logLostData = 0; /* reset at entry */
logState = LogReset;
/* Get the filename for the logfile from the environment */
logFileName = PR_GetEnvSecure( "NSPR_TRACE_LOG" );
if ( logFileName == NULL )
{
PR_LOG( lm, PR_LOG_ERROR,
("RecordTraceEntries: Environment variable not defined. Exiting"));
return NULL;
}
/* Open the logfile */
logFile = PR_Open( logFileName, PR_WRONLY | PR_CREATE_FILE, 0666 );
if ( logFile == NULL )
{
PR_LOG( lm, PR_LOG_ERROR,
("RecordTraceEntries: Cannot open %s as trace log file. OS error: %ld",
logFileName, PR_GetOSError()));
return NULL;
}
return logFile;
} /* end InitializeRecording() */
示例14: nss_load_crl
static SECStatus nss_load_crl(const char* crlfilename)
{
PRFileDesc *infile;
PRFileInfo info;
SECItem filedata = { 0, NULL, 0 };
SECItem crlDER = { 0, NULL, 0 };
char *body;
infile = PR_Open(crlfilename, PR_RDONLY, 0);
if(!infile)
return SECFailure;
if(PR_SUCCESS != PR_GetOpenFileInfo(infile, &info))
goto fail;
if(!SECITEM_AllocItem(NULL, &filedata, info.size + /* zero ended */ 1))
goto fail;
if(info.size != PR_Read(infile, filedata.data, info.size))
goto fail;
/* place a trailing zero right after the visible data */
body = (char*)filedata.data;
body[--filedata.len] = '\0';
body = strstr(body, "-----BEGIN");
if(body) {
/* assume ASCII */
char *trailer;
char *begin = PORT_Strchr(body, '\n');
if(!begin)
begin = PORT_Strchr(body, '\r');
if(!begin)
goto fail;
trailer = strstr(++begin, "-----END");
if(!trailer)
goto fail;
/* retrieve DER from ASCII */
*trailer = '\0';
if(ATOB_ConvertAsciiToItem(&crlDER, begin))
goto fail;
SECITEM_FreeItem(&filedata, PR_FALSE);
}
else
/* assume DER */
crlDER = filedata;
PR_Close(infile);
return nss_cache_crl(&crlDER);
fail:
PR_Close(infile);
SECITEM_FreeItem(&filedata, PR_FALSE);
return SECFailure;
}
示例15: JzipOpen
/****************************************************************
*
* J z i p O p e n
*
* Opens a new ZIP file and creates a new ZIPfile structure to
* control the process of installing files into a zip.
*/
ZIPfile *
JzipOpen(char *filename, char *comment)
{
ZIPfile *zipfile;
PRExplodedTime prtime;
zipfile = PORT_ZAlloc(sizeof(ZIPfile));
if (!zipfile)
out_of_memory();
/* Construct time and date */
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &prtime);
zipfile->date = ((prtime.tm_year - 1980) << 9) |
((prtime.tm_month + 1) << 5) |
prtime.tm_mday;
zipfile->time = (prtime.tm_hour << 11) |
(prtime.tm_min << 5) |
(prtime.tm_sec & 0x3f);
zipfile->fp = NULL;
if (filename &&
(zipfile->fp = PR_Open(filename,
PR_WRONLY |
PR_CREATE_FILE |
PR_TRUNCATE,
0777)) == NULL) {
char *nsprErr;
if (PR_GetErrorTextLength()) {
nsprErr = PR_Malloc(PR_GetErrorTextLength() + 1);
PR_GetErrorText(nsprErr);
} else {
nsprErr = NULL;
}
PR_fprintf(errorFD, "%s: can't open output jar, %s.%s\n",
PROGRAM_NAME,
filename, nsprErr ? nsprErr : "");
if (nsprErr)
PR_Free(nsprErr);
errorCount++;
exit(ERRX);
}
zipfile->list = NULL;
if (filename) {
zipfile->filename = PORT_ZAlloc(strlen(filename) + 1);
if (!zipfile->filename)
out_of_memory();
PORT_Strcpy(zipfile->filename, filename);
}
if (comment) {
zipfile->comment = PORT_ZAlloc(strlen(comment) + 1);
if (!zipfile->comment)
out_of_memory();
PORT_Strcpy(zipfile->comment, comment);
}
return zipfile;
}