本文整理汇总了C++中PR_snprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_snprintf函数的具体用法?C++ PR_snprintf怎么用?C++ PR_snprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_snprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetUniqueMaiAtkTypeName
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;
}
示例2: ResourceAt
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);
}
}
示例3: PR_Now
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);
}
示例4: nssUTF8_Size
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;
}
示例5: printf
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;
}
}
示例6: LOG
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);
}
示例7: ensureTimezone
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;
}
示例8: LoadEnvirFromIni
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;
}
示例9: PL_strncpy
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;
}
示例10: Java_org_mozilla_jss_ssl_SSLSocket_setCipherPreferenceDefault
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;
}
示例11: InitLog
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;
}
示例12: PR_snprintf
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";
}
}
示例13: _PR_MD_OPEN_DIR
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;
}
示例14: _PR_MD_STAT
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;
}
示例15: DLLErrorInternal
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 */