static const char * GetUniqueMaiAtkTypeName(PRUint16 interfacesBits) { #define MAI_ATK_TYPE_NAME_LEN (30) /* 10+sizeof(PRUint16)*8/4+1 < 30 */ static gchar namePrefix[] = "MaiAtkType"; /* size = 10 */ static gchar name[MAI_ATK_TYPE_NAME_LEN + 1]; PR_snprintf(name, MAI_ATK_TYPE_NAME_LEN, "%s%x", namePrefix, interfacesBits); name[MAI_ATK_TYPE_NAME_LEN] = '\0'; MAI_LOG_DEBUG(("MaiWidget::LastedTypeName=%s\n", name)); return name; }
void ResourceQueue::Dump(const char* aPath) { for (uint32_t i = 0; i < uint32_t(GetSize()); ++i) { ResourceItem* item = ResourceAt(i); char buf[255]; PR_snprintf(buf, sizeof(buf), "%s/%08u.bin", aPath, i); FILE* fp = fopen(buf, "wb"); if (!fp) { return; } fwrite(item->mData->Elements(), item->mData->Length(), 1, fp); fclose(fp); } }
void aptCoreTrace::LogBytes(eLogLevel eLevel, const char* data, size_t len) { // Extra spaces for Date, PID, EOL etc #ifdef _WIN32 static const int nEXTRA = 34; #else static const int nEXTRA = 33; #endif if (!mCanLog) return; if (eLevel < mCoreLogLevel) return; PRTime curTime = PR_Now(); PRExplodedTime localTime; PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime); int nTotal = len + nEXTRA + strlen(gsLogLevel[eLevel]); char *buf = new char[nTotal]; if (!buf) return; PRUint32 nWritten = PR_snprintf(buf, nTotal, "%02d:%02d:%02d %02d/%02d/%04d [%6d] [%s] ", // XXX i18n! localTime.tm_hour, localTime.tm_min, localTime.tm_sec, localTime.tm_month+1, localTime.tm_mday, localTime.tm_year, mPid, gsLogLevel[eLevel]); memcpy(buf+nWritten, data, len); nWritten += len; #ifdef _WIN32 buf[nWritten++] = '\r'; #endif buf[nWritten++] = '\n'; #ifdef _DEBUG if (nWritten != nTotal) { char tmp[50]; sprintf(tmp, "nW=%d nT=%d\n", nWritten, nTotal); mLC->WriteLog(tmp, strlen(tmp)); } #endif mLC->WriteNewedLog(buf, nWritten); }
/* ** Perform a three way test against PR_smprintf, PR_snprintf, and sprintf. ** Make sure the results are identical */ static void test_ll(char *pattern, char *spattern, PRInt64 l) { char *s; char buf[200]; int n; /* try all three routines */ s = PR_smprintf(pattern, l); PR_ASSERT(s != 0); n = PR_snprintf(buf, sizeof(buf), pattern, l); PR_ASSERT(n <= sizeof(buf)); #if defined(HAVE_LONG_LONG) sprintf(sbuf, spattern, l); /* compare results */ if ((strncmp(s, buf, sizeof(buf)) != 0) || (strncmp(s, sbuf, sizeof(sbuf)) != 0)) { #if PR_BYTES_PER_LONG == 8 #define FORMAT_SPEC "%ld" #elif defined(WIN16) #define FORMAT_SPEC "%Ld" #elif defined(WIN32) #define FORMAT_SPEC "%I64d" #else #define FORMAT_SPEC "%lld" #endif fprintf(stderr, "pattern='%s' ll=" FORMAT_SPEC "\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n", pattern, l, s, buf, sbuf); printf("FAIL\n"); PR_smprintf_free(s); exit(-1); } PR_smprintf_free(s); #else /* compare results */ if ((strncmp(s, buf, sizeof(buf)) != 0)) { fprintf(stderr, "pattern='%s'\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n", pattern, s, buf, sbuf); printf("FAIL\n"); PR_smprintf_free(s); exit(-1); } PR_smprintf_free(s); #endif }
NSS_IMPLEMENT CK_VERSION nss_dbm_db_get_format_version ( nss_dbm_db_t *db ) { CK_VERSION rv; DBT k, v; int dbrv; char buffer[64]; rv.major = rv.minor = 0; k.data = PREFIX_METADATA "FormatVersion"; k.size = nssUTF8_Size((NSSUTF8 *)k.data, (PRStatus *)NULL); (void)memset(&v, 0, sizeof(v)); /* Locked region */ { if( CKR_OK != NSSCKFWMutex_Lock(db->crustylock) ) { return rv; } dbrv = db->db->get(db->db, &k, &v, 0); if( dbrv == 0 ) { CK_ULONG major = 0, minor = 0; (void)PR_sscanf(v.data, "%ld.%ld", &major, &minor); rv.major = major; rv.minor = minor; } else if( dbrv > 0 ) { (void)PR_snprintf(buffer, sizeof(buffer), "%ld.%ld", nss_dbm_db_format_version.major, nss_dbm_db_format_version.minor); v.data = buffer; v.size = nssUTF8_Size((NSSUTF8 *)v.data, (PRStatus *)NULL); dbrv = db->db->put(db->db, &k, &v, 0); (void)db->db->sync(db->db, 0); rv = nss_dbm_db_format_version; } else { /* No error return.. */ ; } (void)NSSCKFWMutex_Unlock(db->crustylock); } return rv; }
void nsToolkit::GetInterface() { #ifdef DEBUG printf("TK-GI\n"); #endif if(! cached) { char portname[64]; PR_snprintf(portname, sizeof(portname), "event%lx", (long unsigned) mGuiThread); eventport = find_port(portname); cached = true; } }
static void LOG(const char *fmt, ... ) { va_list ap; va_start(ap, fmt); PRUint32 nb = 0; char buf[512]; nb = PR_snprintf(buf, sizeof(buf), "[%u:%p] ", GetPID(), PR_GetCurrentThread()); PR_vsnprintf(buf + nb, sizeof(buf) - nb, fmt, ap); buf[sizeof(buf) - 1] = '\0'; fwrite(buf, strlen(buf), 1, stdout); fflush(stdout); va_end(ap); }
NS_IMETHODIMP calDateTime::ToString(nsACString & aResult) { nsAutoCString tzid; char buffer[256]; ensureTimezone(); mTimezone->GetTzid(tzid); uint32_t const length = PR_snprintf( buffer, sizeof(buffer), "%04hd/%02hd/%02hd %02hd:%02hd:%02hd %s isDate=%01hd nativeTime=%lld", mYear, mMonth + 1, mDay, mHour, mMinute, mSecond, tzid.get(), static_cast<int16_t>(mIsDate), mNativeTime); if (length != static_cast<uint32_t>(-1)) aResult.Assign(buffer, length); return NS_OK; }
void MediaManager::RemoveFromWindowList(uint64_t aWindowID, GetUserMediaCallbackMediaStreamListener *aListener) { NS_ASSERTION(NS_IsMainThread(), "RemoveFromWindowList called off main thread"); // This is defined as safe on an inactive GUMCMSListener aListener->Remove(); // really queues the remove StreamListeners* listeners = GetWindowListeners(aWindowID); if (!listeners) { return; } listeners->RemoveElement(aListener); if (listeners->Length() == 0) { RemoveWindowID(aWindowID); // listeners has been deleted here // get outer windowID nsPIDOMWindow *window = static_cast<nsPIDOMWindow*> (nsGlobalWindow::GetInnerWindowWithId(aWindowID)); if (window) { nsPIDOMWindow *outer = window->GetOuterWindow(); if (outer) { uint64_t outerID = outer->WindowID(); // Notify the UI that this window no longer has gUM active char windowBuffer[32]; PR_snprintf(windowBuffer, sizeof(windowBuffer), "%llu", outerID); nsAutoString data; data.Append(NS_ConvertUTF8toUTF16(windowBuffer)); nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); obs->NotifyObservers(nullptr, "recording-window-ended", data.get()); LOG(("Sent recording-window-ended for window %llu (outer %llu)", aWindowID, outerID)); } else { LOG(("No outer window for inner %llu", aWindowID)); } } else { LOG(("No inner window for %llu", aWindowID)); } } }
SKERR LoadEnvirFromIni(const char * key = NULL) { static char ENV_INI[] = "sk.ini"; static char ENV_SECTION[] = "envir"; SKERR err = noErr; char * homeDir = NULL; err = GetValue(SK_HOME_ENVIR_VAR, &homeDir); if(err != noErr || !homeDir || 0 == PL_strlen(homeDir)) { return err_notfound; } char envirFilename[1024]; PR_snprintf(envirFilename, sizeof envirFilename - 1, "%s/sk.ini", homeDir); SKTextFile iniFile; err = iniFile.SetFileName(envirFilename); if(err != noErr) { SKError(err_failure, "[SKTextFile::LoadEnvirFromIni] " "Failed to set filename, error = %d, envirFilename = %s", err, envirFilename); } IniParser parser(&iniFile); char* pszSection = NULL; char* pszName = NULL; char* pszValue = NULL; PRUint32 line = 0; while ( (err == noErr) && parser.readIniLine(&pszSection, &pszName, &pszValue, &line)) { if(NULL != pszValue && 0 == strcmp(pszSection, ENV_SECTION) && (NULL == key || 0 == strcmp(key, pszName)) ) { err = SetValue(pszName, pszValue); if(err != noErr) SKError(err_failure, "[SKTextFile::LoadEnvirFromIni] " "Stops parsing. Error %d on line %d of %s : %s/%s=%s", err, line, ENV_INI, pszSection, pszName, pszValue); } } return noErr; }
const char *ConfigStore::GetConfig(const char *name) { char buf[256]; char *ret; if (m_root->getSet() ==NULL) { return NULL; } if (PL_strlen(m_substore_name) == 0) { PL_strncpy(buf,name,256); } else { PR_snprintf(buf,256,"%s.%s",m_substore_name,name); } PR_Lock(m_lock); ret = (char *)PL_HashTableLookupConst(m_root->getSet(), buf); PR_Unlock(m_lock); return ret; }
void XFE_AttachmentMenu::add_attachment_menu_items(Widget menu) { const MSG_AttachmentData *data; Arg av [20]; int ac; XmString xmname; if (!m_attachmentData) return; for (data = m_attachmentData; data != NULL; data ++) { char buf[1000]; char *name, *description; Widget button; name = data->real_name; if (name == NULL) name = ""; description = data->description; if (description == NULL) description = ""; PR_snprintf(buf, sizeof(buf), "%s (%s)", name, description); xmname = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG); ac = 0; XtSetArg (av[ac], XmNlabelString, xmname); ac++; XtSetArg (av[ac], XmNuserData, data); ac++; button = XmCreatePushButtonGadget(menu, "openAttachment", av, ac); XtAddCallback(button, XmNactivateCallback, activate_cb, this); XtManageChild(button); XmStringFree(xmname); } }
void aptCoreTrace::Log(eLogLevel eLevel, const char* fmt, ...) { static const int nEOL = 2; if (!mCanLog) return; if (eLevel < mCoreLogLevel) return; PRTime curTime = PR_Now(); PRExplodedTime localTime; PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime); PR_EnterMonitor(mLoggerLock); PRUint32 nWritten = PR_snprintf(mBuf, mBufSize-nEOL, "%02d:%02d:%02d %02d/%02d/%04d [%6d] [%s] ", // XXX i18n! localTime.tm_hour, localTime.tm_min, localTime.tm_sec, localTime.tm_month+1, localTime.tm_mday, localTime.tm_year, mPid, gsLogLevel[eLevel]); va_list arg_ptr; va_start(arg_ptr, fmt); PRUint32 nExtra = PR_vsnprintf(mBuf+nWritten, mBufSize-nWritten-nEOL, fmt, arg_ptr); va_end(arg_ptr); if (nExtra == (PRUint32) (-1)) { //failed? PR_ExitMonitor(mLoggerLock); return; } nWritten += nExtra; #ifdef _WIN32 mBuf[nWritten++] = '\r'; #endif mBuf[nWritten++] = '\n'; mLC->WriteLog(mBuf, nWritten); PR_ExitMonitor(mLoggerLock); }
JNIEXPORT void JNICALL Java_org_mozilla_jss_ssl_SSLSocket_setCipherPreferenceDefault( JNIEnv *env, jclass clazz, jint cipher, jboolean enable) { SECStatus status; /* set the preference */ status = SSL_CipherPrefSetDefault(cipher, enable); if(status != SECSuccess) { char buf[128]; PR_snprintf(buf, 128, "Failed to %s cipher 0x%lx\n", (enable ? "enable" : "disable"), cipher); JSSL_throwSSLSocketException(env, buf); goto finish; } finish: return; }
NS_IMETHODIMP nsDebugImpl::Warning(const char* aMessage, const char* aFile, PRIntn aLine) { InitLog(); char buf[1000]; PR_snprintf(buf, sizeof(buf), "WARNING: %s, file %s, line %d", aMessage, aFile, aLine); // Write out the warning message to the debug log PR_LOG(gDebugLog, PR_LOG_ERROR, ("%s", buf)); // And write it out to the stdout fprintf(stderr, "%s\n", buf); fflush(stderr); return NS_OK; }
void CMapiApi::GetPropTagName( ULONG tag, nsCString& s) { char numStr[256]; PR_snprintf( numStr, 256, "0x%lx, %ld", tag, tag); s = numStr; switch( tag) { #include "mapitagstrs.cpp" } s += ", data: "; switch( PROP_TYPE( tag)) { case PT_UNSPECIFIED: s += "PT_UNSPECIFIED"; break; case PT_NULL: s += "PT_NULL"; break; case PT_I2: s += "PT_I2"; break; case PT_LONG: s += "PT_LONG"; break; case PT_R4: s += "PT_R4"; break; case PT_DOUBLE: s += "PT_DOUBLE"; break; case PT_CURRENCY: s += "PT_CURRENCY"; break; case PT_APPTIME: s += "PT_APPTIME"; break; case PT_ERROR: s += "PT_ERROR"; break; case PT_BOOLEAN: s += "PT_BOOLEAN"; break; case PT_OBJECT: s += "PT_OBJECT"; break; case PT_I8: s += "PT_I8"; break; case PT_STRING8: s += "PT_STRING8"; break; case PT_UNICODE: s += "PT_UNICODE"; break; case PT_SYSTIME: s += "PT_SYSTIME"; break; case PT_CLSID: s += "PT_CLSID"; break; case PT_BINARY: s += "PT_BINARY"; break; case PT_MV_I2: s += "PT_MV_I2"; break; case PT_MV_LONG: s += "PT_MV_LONG"; break; case PT_MV_R4: s += "PT_MV_R4"; break; case PT_MV_DOUBLE: s += "PT_MV_DOUBLE"; break; case PT_MV_CURRENCY: s += "PT_MV_CURRENCY"; break; case PT_MV_APPTIME: s += "PT_MV_APPTIME"; break; case PT_MV_SYSTIME: s += "PT_MV_SYSTIME"; break; case PT_MV_STRING8: s += "PT_MV_STRING8"; break; case PT_MV_BINARY: s += "PT_MV_BINARY"; break; case PT_MV_UNICODE: s += "PT_MV_UNICODE"; break; case PT_MV_CLSID: s += "PT_MV_CLSID"; break; case PT_MV_I8: s += "PT_MV_I8"; break; default: s += "Unknown"; } }
PRStatus _PR_MD_OPEN_DIR(_MDDir *d, const char *name) { char filename[ CCHMAXPATH ]; PRUword numEntries, rc; numEntries = 1; PR_snprintf(filename, CCHMAXPATH, "%s%s%s", name, PR_DIRECTORY_SEPARATOR_STR, "*.*"); FlipSlashes( filename, strlen(filename) ); d->d_hdl = HDIR_CREATE; if (isWSEB) { rc = DosFindFirst( filename, &d->d_hdl, FILE_DIRECTORY | FILE_HIDDEN, &(d->d_entry.large), sizeof(d->d_entry.large), &numEntries, FIL_STANDARDL); } else { rc = DosFindFirst( filename, &d->d_hdl, FILE_DIRECTORY | FILE_HIDDEN, &(d->d_entry.small), sizeof(d->d_entry.small), &numEntries, FIL_STANDARD); } if ( rc != NO_ERROR ) { _PR_MD_MAP_OPENDIR_ERROR(rc); return PR_FAILURE; } d->firstEntry = PR_TRUE; d->magic = _MD_MAGIC_DIR; return PR_SUCCESS; }
PRInt32 _PR_MD_STAT(const char *fn, struct stat *info) { PRInt32 rv; char filename[CCHMAXPATH]; PR_snprintf(filename, CCHMAXPATH, "%s", fn); FlipSlashes(filename, strlen(filename)); rv = _stat((char*)filename, info); if (-1 == rv) { /* * Check for MSVC runtime library _stat() bug. * (It's really a bug in FindFirstFile().) * If a pathname ends in a backslash or slash, * e.g., c:\temp\ or c:/temp/, _stat() will fail. * Note: a pathname ending in a slash (e.g., c:/temp/) * can be handled by _stat() on NT but not on Win95. * * We remove the backslash or slash at the end and * try again. * * Not sure if this happens on OS/2 or not, * but it doesn't hurt to be careful. */ int len = strlen(fn); if (len > 0 && len <= _MAX_PATH && (fn[len - 1] == '\\' || fn[len - 1] == '/')) { char newfn[_MAX_PATH + 1]; strcpy(newfn, fn); newfn[len - 1] = '\0'; rv = _stat(newfn, info); } } if (-1 == rv) { _PR_MD_MAP_STAT_ERROR(errno); } return rv; }
static void DLLErrorInternal(PRIntn oserr) /* ** This whole function, and most of the code in this file, are run ** with a big hairy lock wrapped around it. Not the best of situations, ** but will eventually come up with the right answer. */ { const char *error = NULL; #ifdef USE_DLFCN error = dlerror(); /* $$$ That'll be wrong some of the time - AOF */ #elif defined(HAVE_STRERROR) error = strerror(oserr); /* this should be okay */ #else char errStrBuf[ERR_STR_BUF_LENGTH]; PR_snprintf(errStrBuf, sizeof(errStrBuf), "error %d", oserr); error = errStrBuf; #endif if (NULL != error) PR_SetErrorText(strlen(error), error); } /* DLLErrorInternal */
static void * ldbm_instance_config_instance_dir_get(void *arg) { ldbm_instance *inst = (ldbm_instance *)arg; if (inst->inst_dir_name == NULL) return slapi_ch_strdup(""); else if (inst->inst_parent_dir_name) { int len = strlen(inst->inst_parent_dir_name) + strlen(inst->inst_dir_name) + 2; char *full_inst_dir = (char *)slapi_ch_malloc(len); PR_snprintf(full_inst_dir, len, "%s%c%s", inst->inst_parent_dir_name, get_sep(inst->inst_parent_dir_name), inst->inst_dir_name); return full_inst_dir; } else return slapi_ch_strdup(inst->inst_dir_name); }
void nsMathMLmactionFrame::MouseClick() { if (NS_MATHML_ACTION_TYPE_TOGGLE == mActionType) { if (mChildCount > 1) { int32_t selection = (mSelection == mChildCount)? 1 : mSelection + 1; nsAutoString value; char cbuf[10]; PR_snprintf(cbuf, sizeof(cbuf), "%d", selection); value.AssignASCII(cbuf); bool notify = false; // don't yet notify the document mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::selection_, value, notify); // Now trigger a content-changed reflow... PresContext()->PresShell()-> FrameNeedsReflow(mSelectedFrame, nsIPresShell::eTreeChange, NS_FRAME_IS_DIRTY); } } }
JNIEXPORT jboolean JNICALL Java_org_mozilla_jss_ssl_SSLSocket_getCipherPreferenceDefault( JNIEnv *env, jclass clazz, jint cipher) { SECStatus status; PRBool enabled; /* get the preference */ status = SSL_CipherPrefGetDefault(cipher, &enabled); if(status != SECSuccess) { char buf[128]; PR_snprintf(buf, 128, "Failed to get default preference for " "cipher 0x%lx\n", cipher); JSSL_throwSSLSocketException(env, buf); goto finish; } finish: return enabled; }
void nsUrlClassifierUtils::CanonicalNum(const nsACString& num, uint32_t bytes, bool allowOctal, nsACString& _retval) { _retval.Truncate(); if (num.Length() < 1) { return; } uint32_t val; if (allowOctal && IsOctal(num)) { if (PR_sscanf(PromiseFlatCString(num).get(), "%o", &val) != 1) { return; } } else if (IsDecimal(num)) { if (PR_sscanf(PromiseFlatCString(num).get(), "%u", &val) != 1) { return; } } else if (IsHex(num)) { if (PR_sscanf(PromiseFlatCString(num).get(), num[1] == 'X' ? "0X%x" : "0x%x", &val) != 1) { return; } } else { return; } while (bytes--) { char buf[20]; PR_snprintf(buf, sizeof(buf), "%u", val & 0xff); if (_retval.IsEmpty()) { _retval.Assign(buf); } else { _retval = nsDependentCString(buf) + NS_LITERAL_CSTRING(".") + _retval; } val >>= 8; } }
static void clientThreadFunc(void *arg) { PRUintn port = (PRUintn) arg; PRFileDesc *sock; PRNetAddr addr; char buf[128]; int i; addr.inet.family = AF_INET; addr.inet.port = PR_htons((PRUint16)port); addr.inet.ip = PR_htonl(INADDR_LOOPBACK); PR_snprintf(buf, sizeof(buf), "%hu", addr.inet.port); for (i = 0; i < 5; i++) { sock = PR_NewTCPSocket(); PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT); PR_Write(sock, buf, sizeof(buf)); PR_Close(sock); } }
int ldbm_instance_add_instance_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg) { char *instance_name; struct ldbm_instance *inst= NULL; struct ldbminfo *li= (struct ldbminfo *) arg; int rc = 0; parse_ldbm_instance_entry(entryBefore, &instance_name); /* Make sure we don't create two instances with the same name. */ inst = ldbm_instance_find_by_name(li, instance_name); if (inst != NULL) { LDAPDebug(LDAP_DEBUG_ANY, "WARNING: ldbm instance %s already exists\n", instance_name, 0, 0); if (returntext != NULL) PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "An ldbm instance with the name %s already exists\n", instance_name); if (returncode != NULL) *returncode = LDAP_UNWILLING_TO_PERFORM; slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_ERROR; } if (pb == NULL) { /* called during startup -- do the rest now */ rc = ldbm_instance_generate(li, instance_name, NULL); if (!rc) { inst = ldbm_instance_find_by_name(li, instance_name); rc = ldbm_instance_create_default_user_indexes(inst); } } /* if called during a normal ADD operation, the postadd callback * will do the rest. */ slapi_ch_free((void **)&instance_name); return (rc == 0) ? SLAPI_DSE_CALLBACK_OK : SLAPI_DSE_CALLBACK_ERROR; }
Result Context::createIntegerResult(PRInt64 i) { if (i == 0) return Result(RESULT_INTEGER, PR_FALSE, 0, NULL, "0", 1); if (i == 1) return Result(RESULT_INTEGER, PR_TRUE, 1, NULL, "1", 1); const int size = sizeof("-9223372036854775808"); char *p = (char *) pool_malloc(pool, size); if (p == NULL) return Result::out_of_memory; int len; if (i < INT_MAX || i > INT_MAX) { len = PR_snprintf(p, size, "%lld", i); } else { len = util_itoa(i, p); } return Result(RESULT_INTEGER, (i != 0), i, pool, p, len); }
PKIX_UInt32 pkix_pl_lifecycle_ObjectLeakCheck(int *initObjCountTable) { unsigned int typeCounter = 0; PKIX_UInt32 numObjects = 0; char classNameBuff[128]; char *className = NULL; for (; typeCounter < PKIX_NUMTYPES; typeCounter++) { pkix_ClassTable_Entry *entry = &systemClasses[typeCounter]; PKIX_UInt32 objCountDiff = entry->objCounter; if (initObjCountTable) { PKIX_UInt32 initialCount = initObjCountTable[typeCounter]; objCountDiff = (entry->objCounter > initialCount) ? entry->objCounter - initialCount : 0; } numObjects += objCountDiff; if (!pkixLog || !objCountDiff) { continue; } className = entry->description; if (!className) { className = classNameBuff; PR_snprintf(className, 128, "Unknown(ref %d)", entry->objCounter); } PR_LOG(pkixLog, 1, ("Class %s leaked %d objects of " "size %d bytes, total = %d bytes\n", className, objCountDiff, entry->typeObjectSize, objCountDiff * entry->typeObjectSize)); } return numObjects; }
/* * format_localTime_hr_log will take a time value, and prepare it for * log printing. * * \param time_t t - the time to convert * \param long nsec - the nanoseconds elapsed in the current second. * \param int initsize - the initial buffer size * \param char *buf - The destitation string * \param int *bufsize - The size of the resulting buffer * * \return int success - 0 on correct format, >= 1 on error. */ int format_localTime_hr_log(time_t t, long nsec, int initsize, char *buf, int *bufsize) { long tz; struct tm *tmsp, tms; char tbuf[ *bufsize ]; char sign; /* make sure our buffer will be big enough. Need at least 39 */ if (*bufsize < 39) { /* Should this set the buffer to be something? */ return 1; } (void)localtime_r( &t, &tms ); tmsp = &tms; #ifdef BSD_TIME tz = tmsp->tm_gmtoff; #else /* BSD_TIME */ tz = - timezone; if ( tmsp->tm_isdst ) { tz += 3600; } #endif /* BSD_TIME */ sign = ( tz >= 0 ? '+' : '-' ); if ( tz < 0 ) { tz = -tz; } if (strftime( tbuf, (size_t)*bufsize, "%d/%b/%Y:%H:%M:%S", tmsp) == 0) { return 1; } if (PR_snprintf( buf, *bufsize, "[%s.%09ld %c%02d%02d] ", tbuf, nsec, sign, (int)( tz / 3600 ), (int)( tz % 3600)) == (PRUint32)-1) { return 1; } *bufsize = strlen(buf); return 0; }
/* * format_localTime_log will take a time value, and prepare it for * log printing. * * \param time_t t - the time to convert * \param int initsize - the initial buffer size * \param char *buf - The destitation string * \param int *bufsize - The size of the resulting buffer * * \return int success - 0 on correct format, >= 1 on error. */ int format_localTime_log(time_t t, int initsize, char *buf, int *bufsize) { long tz; struct tm *tmsp, tms; char tbuf[ *bufsize ]; char sign; /* make sure our buffer will be big enough. Need at least 29 */ if (*bufsize < 29) { return 1; } /* nope... painstakingly create the new strftime buffer */ (void)localtime_r( &t, &tms ); tmsp = &tms; #ifdef BSD_TIME tz = tmsp->tm_gmtoff; #else /* BSD_TIME */ tz = - timezone; if ( tmsp->tm_isdst ) { tz += 3600; } #endif /* BSD_TIME */ sign = ( tz >= 0 ? '+' : '-' ); if ( tz < 0 ) { tz = -tz; } if (strftime( tbuf, (size_t)*bufsize, "%d/%b/%Y:%H:%M:%S", tmsp) == 0) { return 1; } if (PR_snprintf( buf, *bufsize, "[%s %c%02d%02d] ", tbuf, sign, (int)( tz / 3600 ), (int)( tz % 3600)) == (PRUint32)-1) { return 1; } *bufsize = strlen(buf); return 0; }
nsresult sbAlbumArtService::GetCacheFileBaseName(const PRUint8* aData, PRUint32 aDataLen, nsACString& aFileBaseName) { TRACE(("sbAlbumArtService[0x%8.x] - GetCacheFileBaseName", this)); // Validate arguments. NS_ASSERTION(aData, "aData is null"); // Function variables. nsresult rv; // Clear file base name. aFileBaseName.Truncate(); // Generate a hash of the image data. nsCAutoString hashValue; nsCOMPtr<nsICryptoHash> cryptoHash = do_CreateInstance("@mozilla.org/security/hash;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = cryptoHash->Init(nsICryptoHash::MD5); NS_ENSURE_SUCCESS(rv, rv); rv = cryptoHash->Update(aData, aDataLen); NS_ENSURE_SUCCESS(rv, rv); rv = cryptoHash->Finish(PR_FALSE, hashValue); NS_ENSURE_SUCCESS(rv, rv); // Produce the image cache file base name. PRUint32 hashLength = hashValue.Length(); PRUint8* hashData = (PRUint8*) hashValue.get(); for (PRUint32 i = 0; i < hashLength; i++) { char hexValue[3]; PR_snprintf(hexValue, 3, "%02x", hashData[i]); aFileBaseName.AppendLiteral(hexValue); } return NS_OK; }