本文整理汇总了C++中PR_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_ASSERT函数的具体用法?C++ PR_ASSERT怎么用?C++ PR_ASSERT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PK11_ImportCRL
CERTSignedCrl* PK11_ImportCRL(PK11SlotInfo * slot, SECItem *derCRL, char *url,
int type, void *wincx, PRInt32 importOptions, PRArenaPool* arena,
PRInt32 decodeoptions)
{
CERTSignedCrl *newCrl, *crl;
SECStatus rv;
CERTCertificate *caCert = NULL;
newCrl = crl = NULL;
do {
newCrl = CERT_DecodeDERCrlWithFlags(arena, derCRL, type,
decodeoptions);
if (newCrl == NULL) {
if (type == SEC_CRL_TYPE) {
/* only promote error when the error code is too generic */
if (PORT_GetError () == SEC_ERROR_BAD_DER)
PORT_SetError(SEC_ERROR_CRL_INVALID);
} else {
PORT_SetError(SEC_ERROR_KRL_INVALID);
}
break;
}
if (0 == (importOptions & CRL_IMPORT_BYPASS_CHECKS)){
CERTCertDBHandle* handle = CERT_GetDefaultCertDB();
PR_ASSERT(handle != NULL);
caCert = CERT_FindCertByName (handle,
&newCrl->crl.derName);
if (caCert == NULL) {
PORT_SetError(SEC_ERROR_UNKNOWN_ISSUER);
break;
}
/* If caCert is a v3 certificate, make sure that it can be used for
crl signing purpose */
rv = CERT_CheckCertUsage (caCert, KU_CRL_SIGN);
if (rv != SECSuccess) {
break;
}
rv = CERT_VerifySignedData(&newCrl->signatureWrap, caCert,
PR_Now(), wincx);
if (rv != SECSuccess) {
if (type == SEC_CRL_TYPE) {
PORT_SetError(SEC_ERROR_CRL_BAD_SIGNATURE);
} else {
PORT_SetError(SEC_ERROR_KRL_BAD_SIGNATURE);
}
break;
}
}
crl = crl_storeCRL(slot, url, newCrl, derCRL, type);
} while (0);
if (crl == NULL) {
SEC_DestroyCrl (newCrl);
}
if (caCert) {
CERT_DestroyCertificate(caCert);
}
return (crl);
}
示例2: hmac_init
void
hmac_init(struct hmac_ctx *ctx,
const struct hash_desc *h,
const u_char *key, size_t key_len)
{
#ifndef HAVE_LIBNSS
int k;
#endif
ctx->h = h;
ctx->hmac_digest_len = h->hash_digest_len;
#ifdef HAVE_LIBNSS
/* DBG(DBG_CRYPT, DBG_log("NSS: hmac init")); */
SECStatus status;
PK11SymKey *symkey=NULL, *tkey1=NULL;
/* PK11SymKey *tkey1=NULL; */
unsigned int klen;
chunk_t hmac_opad, hmac_ipad, hmac_pad;
memcpy(&symkey, key, key_len);
klen = PK11_GetKeyLength(symkey);
hmac_opad = hmac_pads(HMAC_OPAD,HMAC_BUFSIZE);
hmac_ipad = hmac_pads(HMAC_IPAD,HMAC_BUFSIZE);
hmac_pad = hmac_pads(0x00,HMAC_BUFSIZE-klen);
if(klen > HMAC_BUFSIZE)
{
tkey1 = PK11_Derive_osw(symkey, nss_key_derivation_mech(h)
, NULL, CKM_CONCATENATE_BASE_AND_DATA, CKA_DERIVE, 0);
}
else
{
tkey1 = symkey;
}
PK11SymKey *tkey2 = pk11_derive_wrapper_osw(tkey1, CKM_CONCATENATE_BASE_AND_DATA
, hmac_pad,CKM_XOR_BASE_AND_DATA, CKA_DERIVE, HMAC_BUFSIZE);
PR_ASSERT(tkey2!=NULL);
ctx->ikey = pk11_derive_wrapper_osw(tkey2, CKM_XOR_BASE_AND_DATA
, hmac_ipad,nss_hash_mech(h), CKA_DIGEST, 0);
PR_ASSERT(ctx->ikey !=NULL);
ctx->okey = pk11_derive_wrapper_osw(tkey2, CKM_XOR_BASE_AND_DATA
, hmac_opad,nss_hash_mech(h), CKA_DIGEST, 0);
PR_ASSERT(ctx->okey !=NULL);
if(tkey1!=symkey) {
PK11_FreeSymKey(tkey1);
}
PK11_FreeSymKey(tkey2);
freeanychunk(hmac_opad);
freeanychunk(hmac_ipad);
freeanychunk(hmac_pad);
ctx->ctx_nss = PK11_CreateDigestContext(nss_hash_oid(h));
PR_ASSERT(ctx->ctx_nss!=NULL);
status=PK11_DigestBegin(ctx->ctx_nss);
PR_ASSERT(status==SECSuccess);
status=PK11_DigestKey(ctx->ctx_nss, ctx->ikey);
PR_ASSERT(status==SECSuccess);
#else
/* Prepare the two pads for the HMAC */
memset(ctx->buf1, '\0', HMAC_BUFSIZE);
if (key_len <= HMAC_BUFSIZE)
{
memcpy(ctx->buf1, key, key_len);
}
else
{
h->hash_init(&ctx->hash_ctx);
h->hash_update(&ctx->hash_ctx, key, key_len);
h->hash_final(ctx->buf1, &ctx->hash_ctx);
}
memcpy(ctx->buf2, ctx->buf1, HMAC_BUFSIZE);
for (k = 0; k < HMAC_BUFSIZE; k++)
{
ctx->buf1[k] ^= HMAC_IPAD;
ctx->buf2[k] ^= HMAC_OPAD;
}
hmac_reinit(ctx);
#endif
}
示例3: ar_send_res_msg
/*
* ar_send_res_msg
*
* When sending queries to nameservers listed in the resolv.conf file,
* don't send a query to every one, but increase the number sent linearly
* to match the number of resends. This increase only occurs if there are
* multiple nameserver entries in the resolv.conf file.
* The return value is the number of messages successfully sent to
* nameservers or -1 if no successful sends.
*/
int Resolver :: ar_send_res_msg(char *msg, int len, int rcount)
{
int i;
int sent = 0;
#ifdef HPUX
/* VB: _res on HP is thread specific and needs to be initialized
on every thread */
if (!(_res.options & RES_INIT)) {
res_init();
}
#endif
#ifdef Linux
res_init_tls();
#endif
if (!msg)
return -1;
if (_res.options & RES_PRIMARY)
rcount = 1;
rcount = (_res.nscount > rcount) ? rcount : _res.nscount;
if (ar_vc)
{
ar_reinfo.re_sent++;
sent++;
if (PR_Send(afd, msg, len, 0, PR_INTERVAL_NO_TIMEOUT) == -1)
{
int errtmp = errno;
PR_ASSERT(0);
(void)PR_Close(afd);
errno = errtmp;
afd = NULL;
}
}
else
for (i = 0; i < rcount; i++)
{
struct sockaddr_in sin = _res.nsaddr_list[i];
// XXX jpierre is this legal ???
PRNetAddr *paddr = (PRNetAddr *)&sin;
#ifdef AIX
PRNetAddr addr;
/* For AIX struct sockaddr_in { uchar_t sin_len;
* sa_family_t sin_family;
* in_port_t sin_port;
* struct in_addr sin_addr; uchar_t sin_zero[8]; };
* struct in_addr { in_addr_t s_addr; };
* typedef uint32_t in_addr_t;
*
* In NSPR PRNetAddr is :
* union PRNetAddr { struct { PRUint16 family;
* char data[14]; } raw;
* struct { PRUint16 family; PRUint16 port;
* PRUint32 ip; char pad[8]; } inet; ... }
*/
PR_ASSERT(sin.sin_family == AF_INET);
/* xxx strange when request is sent to IPV6 address
* then also address family is AF_INET
*/
memset(&addr, 0, sizeof(addr));
addr.raw.family = sin.sin_family;
addr.inet.family = sin.sin_family;
addr.inet.port = sin.sin_port;
addr.inet.ip = sin.sin_addr.s_addr;
memcpy(addr.inet.pad, sin.sin_zero, 8);
paddr = &addr;
#endif
if (PR_SendTo(afd, msg, len, 0,
paddr,
PR_INTERVAL_NO_TIMEOUT) == len) {
ar_reinfo.re_sent++;
sent++;
}
else
{
PR_ASSERT(0);
}
}
return (sent) ? sent : -1;
}
示例4: getter_AddRefs
PRInt32 nsInstallPatch::Prepare()
{
PRInt32 err;
PRBool deleteOldSrc, flagExists, flagIsFile;
if (mTargetFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
mTargetFile->Exists(&flagExists);
if (flagExists)
{
mTargetFile->IsFile(&flagIsFile);
if (flagIsFile)
{
err = nsInstall::SUCCESS;
}
else
{
err = nsInstall::IS_DIRECTORY;
}
}
else
{
err = nsInstall::DOES_NOT_EXIST;
}
if (err != nsInstall::SUCCESS)
{
return err;
}
err = mInstall->ExtractFileFromJar(*mJarLocation, mTargetFile, getter_AddRefs(mPatchFile));
nsCOMPtr<nsIFile> fileName = nsnull;
//nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );//nsIFileXXX: nsFilePath?
nsVoidKey ikey( HashFilePath( mTargetFile ));
mInstall->GetPatch(&ikey, getter_AddRefs(fileName));
if (fileName != nsnull)
{
deleteOldSrc = PR_TRUE;
}
else
{
fileName = mTargetFile;
deleteOldSrc = PR_FALSE;
}
err = NativePatch( fileName, // the file to patch
mPatchFile, // the patch that was extracted from the jarfile
getter_AddRefs(mPatchedFile)); // the new patched file
// clean up extracted diff data file
mPatchFile->Exists(&flagExists);
if ( (mPatchFile != nsnull) && (flagExists) )
{
mPatchFile->Remove(PR_FALSE);
}
if (err != nsInstall::SUCCESS)
{
// clean up tmp patched file since patching failed
mPatchFile->Exists(&flagExists);
if ((mPatchedFile != nsnull) && (flagExists))
{
mPatchedFile->Remove(PR_FALSE);
}
return err;
}
PR_ASSERT(mPatchedFile != nsnull);
mInstall->AddPatch(&ikey, mPatchedFile );
if ( deleteOldSrc )
{
DeleteFileNowOrSchedule(fileName );
}
return err;
}
示例5: BuildArgArray
//.........这里部分代码省略.........
case 'd':
case 'c':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
break;
case 'e':
case 'f':
case 'g':
nas[ cn ].type = TYPE_DOUBLE;
break;
case 'p':
/* XXX should use cpp */
if (sizeof(void *) == sizeof(PRInt32)) {
nas[ cn ].type = TYPE_UINT32;
} else if (sizeof(void *) == sizeof(PRInt64)) {
nas[ cn ].type = TYPE_UINT64;
} else if (sizeof(void *) == sizeof(PRIntn)) {
nas[ cn ].type = TYPE_UINTN;
} else {
nas[ cn ].type = TYPE_UNKNOWN;
}
break;
case 'C':
case 'S':
case 'E':
case 'G':
/* XXX not supported I suppose */
PR_ASSERT(0);
nas[ cn ].type = TYPE_UNKNOWN;
break;
case 's':
nas[ cn ].type = TYPE_STRING;
break;
case 'n':
nas[ cn ].type = TYPE_INTSTR;
break;
default:
PR_ASSERT(0);
nas[ cn ].type = TYPE_UNKNOWN;
break;
}
/* get a legal para. */
if( nas[ cn ].type == TYPE_UNKNOWN ){
*rv = -1;
break;
}
}
/*
** third pass
** fill the nas[cn].ap
*/
if( *rv < 0 ){
if( nas != nasArray )
示例6: pt_PostNotifies
static void pt_PostNotifies(PRLock *lock, PRBool unlock)
{
PRIntn index, rv;
_PT_Notified post;
_PT_Notified *notified, *prev = NULL;
/*
* Time to actually notify any conditions that were affected
* while the lock was held. Get a copy of the list that's in
* the lock structure and then zero the original. If it's
* linked to other such structures, we own that storage.
*/
post = lock->notified; /* a safe copy; we own the lock */
#if defined(DEBUG)
memset(&lock->notified, 0, sizeof(_PT_Notified)); /* reset */
#else
lock->notified.length = 0; /* these are really sufficient */
lock->notified.link = NULL;
#endif
/* should (may) we release lock before notifying? */
if (unlock)
{
rv = pthread_mutex_unlock(&lock->mutex);
PR_ASSERT(0 == rv);
}
notified = &post; /* this is where we start */
do
{
for (index = 0; index < notified->length; ++index)
{
PRCondVar *cv = notified->cv[index].cv;
PR_ASSERT(NULL != cv);
PR_ASSERT(0 != notified->cv[index].times);
if (-1 == notified->cv[index].times)
{
rv = pthread_cond_broadcast(&cv->cv);
PR_ASSERT(0 == rv);
}
else
{
while (notified->cv[index].times-- > 0)
{
rv = pthread_cond_signal(&cv->cv);
PR_ASSERT(0 == rv);
}
}
#if defined(DEBUG)
pt_debug.cvars_notified += 1;
if (0 > PR_AtomicDecrement(&cv->notify_pending))
{
pt_debug.delayed_cv_deletes += 1;
PR_DestroyCondVar(cv);
}
#else /* defined(DEBUG) */
if (0 > PR_AtomicDecrement(&cv->notify_pending))
PR_DestroyCondVar(cv);
#endif /* defined(DEBUG) */
}
prev = notified;
notified = notified->link;
if (&post != prev) PR_DELETE(prev);
} while (NULL != notified);
} /* pt_PostNotifies */
示例7: print_boulder
/* Print the data for chosen primer pairs to stdout in "boulderio" format. */
void
print_boulder(int io_version,
const p3_global_settings *pa,
const seq_args *sa,
const p3retval *retval,
int explain_flag) {
/* The pointers to warning tag */
char *warning;
/* A place to put a string containing all error messages */
pr_append_str *combined_retval_err = NULL;
/* A small spacer; WARNING this is a fixed size
buffer, but plenty bigger than
log(2^64, 10), the longest character
string that is needed for a 64 bit integer. */
char suffix [100];
/* Pointers for the primer set just printing */
primer_rec *fwd, *rev, *intl;
/* Variables only used for Primer Lists */
int num_fwd, num_rev, num_int, num_pair, num_print;
int print_fwd = 0;
int print_rev = 0;
int print_int = 0;
/* Switches for printing this primer */
int go_fwd = 0;
int go_rev = 0;
int go_int = 0;
/* The number of loop cycles */
int loop_max;
/* That links to the included region */
int i, incl_s = sa->incl_s;
/* This deals with the renaming of the internal oligo */
const char *new_oligo_name = "INTERNAL";
const char *old_oligo_name = "INTERNAL_OLIGO";
char *int_oligo = (char*) new_oligo_name;
/* Check: are all pointers linked to something*/
PR_ASSERT(NULL != pa);
PR_ASSERT(NULL != sa);
if (io_version == 3) {
int_oligo = (char*) old_oligo_name;
}
/* Check if there are warnings and print them */
if ((warning = p3_get_rv_and_gs_warnings(retval, pa)) != NULL) {
printf("PRIMER_WARNING=%s\n", warning);
free(warning);
}
/* Check if a settings file was read an print its id
* Not needed anymore, we do this when we read the setting file. */
/*
if (pa->settings_file_id != NULL) {
printf("P3_FILE_ID=%s\n", pa->settings_file_id);
free(warning);
}
*/
combined_retval_err = create_pr_append_str();
if (NULL == combined_retval_err) exit(-2); /* Out of memory */
if (pr_append_new_chunk_external(combined_retval_err,
retval->glob_err.data))
exit(-2);
if (pr_append_new_chunk_external(combined_retval_err,
retval->per_sequence_err.data))
exit(-2);
/* Check if there are errors, print and return */
if (!pr_is_empty(combined_retval_err)) {
print_boulder_error(pr_append_str_chars(combined_retval_err));
destroy_pr_append_str(combined_retval_err);
return;
}
destroy_pr_append_str(combined_retval_err);
/* Get how many primers are in the array */
num_fwd = retval->fwd.num_elem;
num_rev = retval->rev.num_elem;
num_int = retval->intl.num_elem;
num_pair = retval->best_pairs.num_pairs;
/* Prints out statistics about the primers */
if (explain_flag) print_all_explain(pa, sa, retval, io_version);
/* Print out the stop codon if a reading frame was specified */
if (!PR_START_CODON_POS_IS_NULL(sa))
printf("PRIMER_STOP_CODON_POSITION=%d\n", retval->stop_codon_pos);
/* How often has the loop to be done? */
//.........这里部分代码省略.........
示例8: _PR_UnblockLockWaiter
/*
** Unblock the first runnable waiting thread. Skip over
** threads that are trying to be suspended
** Note: Caller must hold _PR_LOCK_LOCK()
*/
void _PR_UnblockLockWaiter(PRLock *lock)
{
PRThread *t = NULL;
PRThread *me;
PRCList *q;
q = lock->waitQ.next;
PR_ASSERT(q != &lock->waitQ);
while (q != &lock->waitQ) {
/* Unblock first waiter */
t = _PR_THREAD_CONDQ_PTR(q);
/*
** We are about to change the thread's state to runnable and for local
** threads, we are going to assign a cpu to it. So, protect thread's
** data structure.
*/
_PR_THREAD_LOCK(t);
if (t->flags & _PR_SUSPENDING) {
q = q->next;
_PR_THREAD_UNLOCK(t);
continue;
}
/* Found a runnable thread */
PR_ASSERT(t->state == _PR_LOCK_WAIT);
PR_ASSERT(t->wait.lock == lock);
t->wait.lock = 0;
PR_REMOVE_LINK(&t->waitQLinks); /* take it off lock's waitQ */
/*
** If this is a native thread, nothing else to do except to wake it
** up by calling the machine dependent wakeup routine.
**
** If this is a local thread, we need to assign it a cpu and
** put the thread on that cpu's run queue. There are two cases to
** take care of. If the currently running thread is also a local
** thread, we just assign our own cpu to that thread and put it on
** the cpu's run queue. If the the currently running thread is a
** native thread, we assign the primordial cpu to it (on NT,
** MD_WAKEUP handles the cpu assignment).
*/
if ( !_PR_IS_NATIVE_THREAD(t) ) {
t->state = _PR_RUNNABLE;
me = _PR_MD_CURRENT_THREAD();
_PR_AddThreadToRunQ(me, t);
_PR_THREAD_UNLOCK(t);
} else {
t->state = _PR_RUNNING;
_PR_THREAD_UNLOCK(t);
}
_PR_MD_WAKEUP_WAITER(t);
break;
}
return;
}
示例9: main
PRIntn main(PRIntn argc, char *argv[])
{
PRThread *tJitter;
PRThread *tAccept;
PRThread *tConnect;
PRStatus rv;
/* This test if valid for WinNT only! */
#if !defined(WINNT)
return 0;
#endif
{
/*
** Get command line options
*/
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "hdrvj:");
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
if (PL_OPT_BAD == os) continue;
switch (opt->option)
{
case 'd': /* debug */
debug = 1;
msgLevel = PR_LOG_ERROR;
break;
case 'v': /* verbose mode */
verbose = 1;
msgLevel = PR_LOG_DEBUG;
break;
case 'j':
jitter = atoi(opt->value);
if ( jitter == 0)
jitter = JITTER_DEFAULT;
break;
case 'r':
resume = PR_TRUE;
break;
case 'h': /* help message */
Help();
break;
default:
break;
}
}
PL_DestroyOptState(opt);
}
lm = PR_NewLogModule("Test"); /* Initialize logging */
/* set concurrency */
PR_SetConcurrency( 4 );
/* setup thread synchronization mechanics */
ml = PR_NewLock();
cv = PR_NewCondVar( ml );
/* setup a tcp socket */
memset(&listenAddr, 0, sizeof(listenAddr));
rv = PR_InitializeNetAddr(PR_IpAddrAny, BASE_PORT, &listenAddr);
PR_ASSERT( PR_SUCCESS == rv );
listenSock = PR_NewTCPSocket();
PR_ASSERT( listenSock );
rv = PR_Bind( listenSock, &listenAddr);
PR_ASSERT( PR_SUCCESS == rv );
rv = PR_Listen( listenSock, 5 );
PR_ASSERT( PR_SUCCESS == rv );
/* open a file for writing, provoke bug */
file1 = PR_Open("xxxTestFile", PR_CREATE_FILE | PR_RDWR, 666);
/* create Connect thread */
tConnect = PR_CreateThread(
PR_USER_THREAD, ConnectThread, NULL,
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tConnect );
/* create jitter off thread */
tJitter = PR_CreateThread(
PR_USER_THREAD, JitterThread, NULL,
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tJitter );
/* create acceptread thread */
tAccept = PR_CreateThread(
PR_USER_THREAD, AcceptThread, NULL,
PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tAccept );
/* wait for all threads to quit, then terminate gracefully */
PR_JoinThread( tConnect );
PR_JoinThread( tAccept );
//.........这里部分代码省略.........
示例10: PR_IMPLEMENT
/*
** Unlock the lock.
*/
PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
{
PRCList *q;
PRThreadPriority pri, boost;
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(lock != NULL);
PR_ASSERT(lock->owner == me);
PR_ASSERT(me != suspendAllThread);
PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));
if (lock->owner != me) {
return PR_FAILURE;
}
#ifdef _PR_GLOBAL_THREADS_ONLY
lock->owner = 0;
_PR_MD_UNLOCK(&lock->ilock);
return PR_SUCCESS;
#else /* _PR_GLOBAL_THREADS_ONLY */
if (_native_threads_only) {
lock->owner = 0;
_PR_MD_UNLOCK(&lock->ilock);
return PR_SUCCESS;
}
if (!_PR_IS_NATIVE_THREAD(me))
_PR_INTSOFF(is);
_PR_LOCK_LOCK(lock);
/* Remove the lock from the owning thread's lock list */
PR_REMOVE_LINK(&lock->links);
pri = lock->priority;
boost = lock->boostPriority;
if (boost > pri) {
/*
** We received a priority boost during the time we held the lock.
** We need to figure out what priority to move to by scanning
** down our list of lock's that we are still holding and using
** the highest boosted priority found.
*/
q = me->lockList.next;
while (q != &me->lockList) {
PRLock *ll = _PR_LOCK_PTR(q);
if (ll->boostPriority > pri) {
pri = ll->boostPriority;
}
q = q->next;
}
if (pri != me->priority) {
_PR_SetThreadPriority(me, pri);
}
}
/* Unblock the first waiting thread */
q = lock->waitQ.next;
if (q != &lock->waitQ)
_PR_UnblockLockWaiter(lock);
lock->boostPriority = PR_PRIORITY_LOW;
lock->owner = 0;
_PR_LOCK_UNLOCK(lock);
if (!_PR_IS_NATIVE_THREAD(me))
_PR_INTSON(is);
return PR_SUCCESS;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
示例11: _PR_FreeLock
void _PR_FreeLock(PRLock *lock)
{
PR_ASSERT(lock->owner == 0);
_PR_MD_FREE_LOCK(&lock->ilock);
}
示例12: PR_IMPLEMENT
PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
{
PLArena *a;
char *rp; /* returned pointer */
PR_ASSERT((nb & pool->mask) == 0);
nb = (PRUword)PL_ARENA_ALIGN(pool, nb); /* force alignment */
/* attempt to allocate from arenas at pool->current */
{
a = pool->current;
do {
if ( a->avail +nb <= a->limit ) {
pool->current = a;
rp = (char *)a->avail;
a->avail += nb;
return rp;
}
} while( NULL != (a = a->next) );
}
/* attempt to allocate from arena_freelist */
{
PLArena *p; /* previous pointer, for unlinking from freelist */
/* lock the arena_freelist. Make access to the freelist MT-Safe */
if ( PR_FAILURE == LockArena())
return(0);
for ( a = arena_freelist, p = NULL; a != NULL ; p = a, a = a->next ) {
if ( a->base +nb <= a->limit ) {
if ( p == NULL )
arena_freelist = a->next;
else
p->next = a->next;
UnlockArena();
a->avail = a->base;
rp = (char *)a->avail;
a->avail += nb;
/* the newly allocated arena is linked after pool->current
* and becomes pool->current */
a->next = pool->current->next;
pool->current->next = a;
pool->current = a;
if ( NULL == pool->first.next )
pool->first.next = a;
return(rp);
}
}
UnlockArena();
}
/* attempt to allocate from the heap */
{
PRUint32 sz = PR_MAX(pool->arenasize, nb);
sz += sizeof *a + pool->mask; /* header and alignment slop */
a = (PLArena*)PR_MALLOC(sz);
if ( NULL != a ) {
a->limit = (PRUword)a + sz;
a->base = a->avail = (PRUword)PL_ARENA_ALIGN(pool, a + 1);
rp = (char *)a->avail;
a->avail += nb;
/* the newly allocated arena is linked after pool->current
* and becomes pool->current */
a->next = pool->current->next;
pool->current->next = a;
pool->current = a;
if ( NULL == pool->first.next )
pool->first.next = a;
PL_COUNT_ARENA(pool,++);
COUNT(pool, nmallocs);
return(rp);
}
}
示例13: MsgGetFileStream
// We let the caller close the file in case he's updating a lot of flags
// and we don't want to open and close the file every time through.
// As an experiment, try caching the fid in the db as m_folderFile.
// If this is set, use it but don't return *pFid.
void nsMailDatabase::UpdateFolderFlag(nsIMsgDBHdr *mailHdr, PRBool bSet,
MsgFlags flag, nsIOutputStream **ppFileStream)
{
static char buf[50];
PRInt64 folderStreamPos = 0; //saves the folderStream pos in case we are sharing the stream with other code
nsIOutputStream *fileStream = (m_folderStream) ? m_folderStream.get() : *ppFileStream;
PRUint32 offset;
(void)mailHdr->GetStatusOffset(&offset);
nsCOMPtr <nsISeekableStream> seekableStream;
nsresult rv;
if (offset > 0)
{
if (fileStream == NULL)
{
rv = MsgGetFileStream(m_folderFile, &fileStream);
if (NS_FAILED(rv))
return;
seekableStream = do_QueryInterface(fileStream);
}
else if (!m_ownFolderStream)
{
m_folderStream->Flush();
seekableStream = do_QueryInterface(fileStream);
seekableStream->Tell(&folderStreamPos);
}
else
seekableStream = do_QueryInterface(m_folderStream);
if (fileStream)
{
PRUint32 msgOffset;
(void)mailHdr->GetMessageOffset(&msgOffset);
PRUint32 statusPos = offset + msgOffset;
PR_ASSERT(offset < 10000);
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, statusPos);
buf[0] = '\0';
nsCOMPtr <nsIInputStream> inputStream = do_QueryInterface(fileStream);
PRUint32 bytesRead;
if (NS_SUCCEEDED(inputStream->Read(buf, X_MOZILLA_STATUS_LEN + 6, &bytesRead)))
{
buf[bytesRead] = '\0';
if (strncmp(buf, X_MOZILLA_STATUS, X_MOZILLA_STATUS_LEN) == 0 &&
strncmp(buf + X_MOZILLA_STATUS_LEN, ": ", 2) == 0 &&
strlen(buf) >= X_MOZILLA_STATUS_LEN + 6)
{
PRUint32 flags;
PRUint32 bytesWritten;
(void)mailHdr->GetFlags(&flags);
if (!(flags & MSG_FLAG_EXPUNGED))
{
int i;
char *p = buf + X_MOZILLA_STATUS_LEN + 2;
for (i=0, flags = 0; i<4; i++, p++)
{
flags = (flags << 4) | msg_UnHex(*p);
}
PRUint32 curFlags;
(void)mailHdr->GetFlags(&curFlags);
flags = (flags & MSG_FLAG_QUEUED) |
(curFlags & ~MSG_FLAG_RUNTIME_ONLY);
}
else
{
flags &= ~MSG_FLAG_RUNTIME_ONLY;
}
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, statusPos);
// We are filing out x-mozilla-status flags here
PR_snprintf(buf, sizeof(buf), X_MOZILLA_STATUS_FORMAT,
flags & 0x0000FFFF);
PRInt32 lineLen = PL_strlen(buf);
PRUint32 status2Pos = statusPos + lineLen + MSG_LINEBREAK_LEN;
fileStream->Write(buf, lineLen, &bytesWritten);
// time to upate x-mozilla-status2
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, status2Pos);
if (NS_SUCCEEDED(inputStream->Read(buf, X_MOZILLA_STATUS2_LEN + 10, &bytesRead)))
{
if (strncmp(buf, X_MOZILLA_STATUS2, X_MOZILLA_STATUS2_LEN) == 0 &&
strncmp(buf + X_MOZILLA_STATUS2_LEN, ": ", 2) == 0 &&
strlen(buf) >= X_MOZILLA_STATUS2_LEN + 10)
{
PRUint32 dbFlags;
(void)mailHdr->GetFlags(&dbFlags);
dbFlags &= 0xFFFF0000;
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, status2Pos);
PR_snprintf(buf, sizeof(buf), X_MOZILLA_STATUS2_FORMAT, dbFlags);
fileStream->Write(buf, PL_strlen(buf), &bytesWritten);
}
}
} else
{
//.........这里部分代码省略.........
示例14: ForkAndExec
//.........这里部分代码省略.........
}
#endif /* VMS */
#ifdef AIX
process->md.pid = (*pr_wp.forkptr)();
#elif defined(NTO) || defined(SYMBIAN)
/*
* fork() & exec() does not work in a multithreaded process.
* Use spawn() instead.
*/
{
int fd_map[3] = { 0, 1, 2 };
if (attr) {
if (attr->stdinFd && attr->stdinFd->secret->md.osfd != 0) {
fd_map[0] = dup(attr->stdinFd->secret->md.osfd);
flags = fcntl(fd_map[0], F_GETFL, 0);
if (flags & O_NONBLOCK)
fcntl(fd_map[0], F_SETFL, flags & ~O_NONBLOCK);
}
if (attr->stdoutFd && attr->stdoutFd->secret->md.osfd != 1) {
fd_map[1] = dup(attr->stdoutFd->secret->md.osfd);
flags = fcntl(fd_map[1], F_GETFL, 0);
if (flags & O_NONBLOCK)
fcntl(fd_map[1], F_SETFL, flags & ~O_NONBLOCK);
}
if (attr->stderrFd && attr->stderrFd->secret->md.osfd != 2) {
fd_map[2] = dup(attr->stderrFd->secret->md.osfd);
flags = fcntl(fd_map[2], F_GETFL, 0);
if (flags & O_NONBLOCK)
fcntl(fd_map[2], F_SETFL, flags & ~O_NONBLOCK);
}
PR_ASSERT(attr->currentDirectory == NULL); /* not implemented */
}
#ifdef SYMBIAN
/* In Symbian OS, we use posix_spawn instead of fork() and exec() */
posix_spawn(&(process->md.pid), path, NULL, NULL, argv, childEnvp);
#else
process->md.pid = spawn(path, 3, fd_map, NULL, argv, childEnvp);
#endif
if (fd_map[0] != 0)
close(fd_map[0]);
if (fd_map[1] != 1)
close(fd_map[1]);
if (fd_map[2] != 2)
close(fd_map[2]);
}
#else
process->md.pid = fork();
#endif
if ((pid_t) -1 == process->md.pid) {
PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, errno);
PR_DELETE(process);
if (newEnvp) {
PR_DELETE(newEnvp);
}
return NULL;
} else if (0 == process->md.pid) { /* the child process */
/*
* If the child process needs to exit, it must call _exit().
* Do not call exit(), because exit() will flush and close
* the standard I/O file descriptors, and hence corrupt
* the parent process's standard I/O data structures.
示例15: PR_IMPLEMENT
PR_IMPLEMENT(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar)
{
PR_ASSERT(cvar != NULL);
pt_PostNotifyToCvar(cvar, PR_TRUE);
return PR_SUCCESS;
} /* PR_NotifyAllCondVar */