本文整理汇总了C++中PR_sscanf函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_sscanf函数的具体用法?C++ PR_sscanf怎么用?C++ PR_sscanf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_sscanf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main(int argc, char* argv[])
{
if (test_common_init(&argc, &argv) != 0)
return -1;
nsresult rv;
if (argc < 4) {
printf("usage: %s <file-to-read> <start-offset> <read-length>\n", argv[0]);
return -1;
}
char* fileName = argv[1];
int64_t offset, length;
int err = PR_sscanf(argv[2], "%lld", &offset);
if (err == -1) {
printf("Start offset must be an integer!\n");
return 1;
}
err = PR_sscanf(argv[3], "%lld", &length);
if (err == -1) {
printf("Length must be an integer!\n");
return 1;
}
{
nsCOMPtr<nsIServiceManager> servMan;
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
if (registrar)
registrar->AutoRegister(nullptr);
#if defined(PR_LOGGING)
gTestLog = PR_NewLogModule("Test");
#endif
nsCOMPtr<nsIFile> file;
rv = NS_NewNativeLocalFile(nsDependentCString(fileName), false, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
rv = RunTest(file, offset, length);
NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");
// give background threads a chance to finish whatever work they may
// be doing.
PR_Sleep(PR_SecondsToInterval(1));
} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
rv = NS_ShutdownXPCOM(nullptr);
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
return NS_OK;
}
示例2: narrow
NS_IMETHODIMP sbDatetimePropertyInfo::MakeSearchable(const nsAString & aValue, nsAString & _retval)
{
nsresult rv;
PRInt64 value = 0;
NS_ConvertUTF16toUTF8 narrow(aValue);
_retval = aValue;
_retval.StripWhitespace();
sbSimpleAutoLock lock(mMinMaxDateTimeLock);
if(PR_sscanf(narrow.get(), gsFmtRadix10, &value) != 1) {
_retval = EmptyString();
return NS_ERROR_INVALID_ARG;
}
char out[32] = {0};
if(PR_snprintf(out, 32, gsSortFmtRadix10, value) == (PRUint32)-1) {
rv = NS_ERROR_FAILURE;
_retval = EmptyString();
}
else {
NS_ConvertUTF8toUTF16 wide(out);
rv = NS_OK;
_retval = wide;
}
return rv;
}
示例3: narrow
int32_t
nsAString::ToInteger(nsresult *aErrorCode, uint32_t aRadix) const
{
NS_ConvertUTF16toUTF8 narrow(*this);
const char *fmt;
switch (aRadix) {
case 10:
fmt = "%i";
break;
case 16:
fmt = "%x";
break;
default:
NS_ERROR("Unrecognized radix!");
*aErrorCode = NS_ERROR_INVALID_ARG;
return 0;
}
int32_t result = 0;
if (PR_sscanf(narrow.get(), fmt, &result) == 1)
*aErrorCode = NS_OK;
else
*aErrorCode = NS_ERROR_FAILURE;
return result;
}
示例4: switch
int64_t
nsACString::ToInteger64(nsresult *aErrorCode, uint32_t aRadix) const
{
const char *fmt;
switch (aRadix) {
case 10:
fmt = "%lli";
break;
case 16:
fmt = "%llx";
break;
default:
NS_ERROR("Unrecognized radix!");
*aErrorCode = NS_ERROR_INVALID_ARG;
return 0;
}
int64_t result = 0;
if (PR_sscanf(nsCString(*this).get(), fmt, &result) == 1)
*aErrorCode = NS_OK;
else
*aErrorCode = NS_ERROR_FAILURE;
return result;
}
示例5: NS_WARNING
/**
* Reads one table of results from the response. Leaves begin pointing at the
* next table.
*/
nsresult
nsUrlClassifierHashCompleterRequest::HandleTable(nsACString::const_iterator& begin,
const nsACString::const_iterator& end)
{
nsACString::const_iterator iter;
iter = begin;
if (!FindCharInReadable(':', iter, end)) {
// No table line.
NS_WARNING("Received badly-formatted gethash response.");
return NS_ERROR_FAILURE;
}
const nsCSubstring& tableName = Substring(begin, iter);
iter++;
begin = iter;
if (!FindCharInReadable('\n', iter, end)) {
// Unterminated header line.
NS_WARNING("Received badly-formatted gethash response.");
return NS_ERROR_FAILURE;
}
const nsCSubstring& remaining = Substring(begin, iter);
iter++;
begin = iter;
PRUint32 chunkId;
PRInt32 size;
if (PR_sscanf(PromiseFlatCString(remaining).get(),
"%u:%d", &chunkId, &size) != 2) {
NS_WARNING("Received badly-formatted gethash response.");
return NS_ERROR_FAILURE;
}
if (size % COMPLETE_LENGTH != 0) {
NS_WARNING("Unexpected gethash response length");
return NS_ERROR_FAILURE;
}
// begin now refers to the hash data.
if (begin.size_forward() < size) {
NS_WARNING("Response does not match the expected response length.");
return NS_ERROR_FAILURE;
}
for (PRInt32 i = 0; i < (size / COMPLETE_LENGTH); i++) {
// Read the complete hash.
iter.advance(COMPLETE_LENGTH);
nsresult rv = HandleItem(Substring(begin, iter), tableName, chunkId);
NS_ENSURE_SUCCESS(rv, rv);
begin = iter;
}
// begin now points at the end of the hash data.
return NS_OK;
}
示例6: ParseVersion
static PRUint32 ParseVersion(const char *versionStr)
{
PRUint16 major, minor;
if (PR_sscanf(versionStr, "%hu.%hu", &major, &minor) != 2) {
NS_WARNING("invalid version string");
return 0;
}
return PRUint32(major) << 16 | PRUint32(minor);
}
示例7: while
nsresult
mozSqlResultODBC::BuildRows()
{
while (SQL_SUCCEEDED(SQLFetch(mResult))) {
nsCOMPtr<nsIRDFResource> resource;
nsresult rv = gRDFService->GetAnonymousResource(getter_AddRefs(resource));
if (NS_FAILED(rv)) return rv;
Row* row = Row::Create(mAllocator, resource, mColumnInfo);
for (PRInt32 j = 0; j < mColumnInfo.Count(); j++) {
SQLINTEGER indicator;
SQLCHAR buf[512];
if(SQL_SUCCEEDED(SQLGetData(mResult, j+1, SQL_C_TCHAR, buf, sizeof(buf), &indicator)) && indicator != SQL_NULL_DATA) {
char* value = (char*)buf;
Cell* cell = row->mCells[j];
cell->SetNull(PR_FALSE);
PRInt32 type = cell->GetType();
if (type == mozISqlResult::TYPE_STRING)
cell->SetString(ToNewUnicode(nsDependentCString(value)));
else if (type == mozISqlResult::TYPE_INT)
PR_sscanf(value, "%d", &cell->mInt);
else if (type == mozISqlResult::TYPE_FLOAT)
PR_sscanf(value, "%f", &cell->mFloat);
else if (type == mozISqlResult::TYPE_DECIMAL)
PR_sscanf(value, "%f", &cell->mFloat);
else if (type == mozISqlResult::TYPE_DATE ||
type == mozISqlResult::TYPE_TIME ||
type == mozISqlResult::TYPE_DATETIME)
PR_ParseTimeString(value, PR_FALSE, &cell->mDate);
else if (type == mozISqlResult::TYPE_BOOL)
cell->mBool = !strcmp(value, "t");
}
}
mRows.AppendElement(row);
nsVoidKey key(resource);
mSources.Put(&key, row);
}
return NS_OK;
}
示例8:
NS_IMETHODIMP
nsInstallVersion::Init(const nsString& version)
{
mMajor = mMinor = mRelease = mBuild = 0;
// nsString is a flat string
if (PR_sscanf(NS_ConvertUTF16toUTF8(version).get(),"%d.%d.%d.%d",&mMajor,&mMinor,&mRelease,&mBuild) < 1)
return NS_ERROR_UNEXPECTED;
return NS_OK;
}
示例9: if
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;
}
}
示例10: while
nsresult
mozSqlResultMysql::BuildRows()
{
MYSQL_ROW resultrow;
while ((resultrow = mysql_fetch_row(mResult))){
nsCOMPtr<nsIRDFResource> resource;
nsresult rv = gRDFService->GetAnonymousResource(getter_AddRefs(resource));
if (NS_FAILED(rv)) return rv;
Row* row = Row::Create(mAllocator, resource, mColumnInfo);
for (PRInt32 j = 0; j < mColumnInfo.Count(); j++) {
char* value = resultrow[j];
if (value){
Cell* cell = row->mCells[j];
cell->SetNull(PR_FALSE);
PRInt32 type = cell->GetType();
if (type == mozISqlResult::TYPE_STRING)
cell->SetString(UTF8ToNewUnicode(nsDependentCString(value)));
else if (type == mozISqlResult::TYPE_INT)
PR_sscanf(value, "%d", &cell->mInt);
else if (type == mozISqlResult::TYPE_FLOAT)
PR_sscanf(value, "%f", &cell->mFloat);
else if (type == mozISqlResult::TYPE_DECIMAL)
PR_sscanf(value, "%f", &cell->mFloat);
else if (type == mozISqlResult::TYPE_DATE ||
type == mozISqlResult::TYPE_TIME ||
type == mozISqlResult::TYPE_DATETIME)
PR_ParseTimeString(value, PR_FALSE, &cell->mDate);
else if (type == mozISqlResult::TYPE_BOOL)
cell->mBool = !strcmp(value, "t");
}
}
mRows.AppendElement(row);
nsVoidKey key(resource);
mSources.Put(&key, row);
}
return NS_OK;
}
示例11: PR_sscanf
nsresult
SdpHelper::GetComponent(const std::string& candidate, size_t* component)
{
unsigned int temp;
int32_t result = PR_sscanf(candidate.c_str(), "%*s %u", &temp);
if (result == 1) {
*component = temp;
return NS_OK;
}
SDP_SET_ERROR("Malformed ICE candidate: " << candidate);
return NS_ERROR_INVALID_ARG;
}
示例12: return
/* static */ bool
LookupCache::IsCanonicalizedIP(const nsACString& aHost)
{
// The canonicalization process will have left IP addresses in dotted
// decimal with no surprises.
uint32_t i1, i2, i3, i4;
char c;
if (PR_sscanf(PromiseFlatCString(aHost).get(), "%u.%u.%u.%u%c",
&i1, &i2, &i3, &i4, &c) == 4) {
return (i1 <= 0xFF && i2 <= 0xFF && i3 <= 0xFF && i4 <= 0xFF);
}
return false;
}
示例13: get_post_assertion_data
char * get_post_assertion_data(Session *sn, Request *rq, char *url)
{
int i = 0;
char *body = NULL;
int cl = 0;
char *cl_str = NULL;
/**
* content length and body
*
* note: memory allocated in here should be released by
* other function such as: "policy_unregister_post"
*/
request_header("content-length", &cl_str, sn, rq);
if(cl_str == NULL)
cl_str = pblock_findval("content-length", rq->headers);
if(cl_str == NULL)
return body;
if(PR_sscanf(cl_str, "%ld", &cl) == 1) {
body = (char *)malloc(cl + 1);
if(body != NULL){
for (i = 0; i < cl; i++) {
int ch = netbuf_getc(sn->inbuf);
if (ch==IO_ERROR || ch == IO_EOF) {
break;
}
body[i] = ch;
}
body[i] = '\0';
}
} else {
am_web_log_error("Error reading POST content body");
}
am_web_log_max_debug("Read POST content body : %s", body);
/**
* need to reset content length before redirect,
* otherwise, web server will wait for serveral minutes
* for non existant data
*/
param_free(pblock_remove("content-length", rq->headers));
pblock_nvinsert("content-length", "0", rq->headers);
return body;
}
示例14: TimelineInit
PRStatus TimelineInit(void)
{
char *timeStr;
char *fileName;
PRInt32 secs, msecs;
PRFileDesc *fd;
PRInt64 tmp1, tmp2;
PRStatus status = PR_NewThreadPrivateIndex( &gTLSIndex, ThreadDestruct );
NS_WARN_IF_FALSE(status==0, "TimelineService could not allocate TLS storage.");
timeStr = PR_GetEnv("NS_TIMELINE_INIT_TIME");
#ifdef XP_MAC
initInterval = PR_IntervalNow();
#endif
// NS_TIMELINE_INIT_TIME only makes sense for the main thread, so if it
// exists, set it there. If not, let normal thread management code take
// care of setting the init time.
if (timeStr != NULL && 2 == PR_sscanf(timeStr, "%d.%d", &secs, &msecs)) {
PRTime &initTime = GetThisThreadData()->initTime;
LL_MUL(tmp1, (PRInt64)secs, 1000000);
LL_MUL(tmp2, (PRInt64)msecs, 1000);
LL_ADD(initTime, tmp1, tmp2);
#ifdef XP_MAC
initInterval -= PR_MicrosecondsToInterval(
(PRUint32)(PR_Now() - initTime));
#endif
}
// Get the log file.
#ifdef XP_MAC
fileName = "timeline.txt";
#else
fileName = PR_GetEnv("NS_TIMELINE_LOG_FILE");
#endif
if (fileName != NULL
&& (fd = PR_Open(fileName, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
0666)) != NULL) {
timelineFD = fd;
PR_fprintf(fd,
"NOTE: due to asynchrony, the indentation that you see does"
" not necessarily correspond to nesting in the code.\n\n");
}
// Runtime disable of timeline
if (PR_GetEnv("NS_TIMELINE_ENABLE"))
gTimelineDisabled = PR_FALSE;
return PR_SUCCESS;
}
示例15: 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;
}