NSPR Reference Previous Contents Next |
stdlib
offering. The routines offered are thread aware and do place extra burdens on the
clients to deal with resource allocation and deallocation.
Formatting Specification
Output Functions
Scanning Function
format
string. The format
string contains two types of objects: ordinary
characters, which are copied to the output stream, and conversion specifications,
each of which causes conversion and printing of the next successive argument of
the calling function. Each conversion specification begins with a percent character
(%
) and ends with a conversion character. Between the percent and the conversion
character there can be, in order:
A number that specifies the minimum field width. The converted argument will be printed in a field at least this wide. If necessary, it will be padded on the left (or right, if left adjustment is called for) to make up the field width.
A period, which separates the field width from the precision.
A number, the precision, that specifies the maximum number of characters to be printed for a string, or the number of digits after the decimal point of a floating point value, or the minimum number of digits for an integer.
An h
if the integer is to be printed as a 16 bit value, a l
if 32 bits, or ll
if 64 bits.
PR_snprintf
PR_smprintf
PR_sprintf_append
PR_smprintf_free
PR_sxprintf
PR_fprintf
Each of these functions has a corresponding version implemented with a variable length argument list:
va_list Versions of Output Functions
PRUint32 PR_snprintf (
char *out,
PRUint32 outlen,
const char *fmt,
...);
NULL
terminator, or NULL
is at the end of the buffer.
char* PR_smprintf (
const char *fmt,
...);
fmt
|
The string that is used as the formatting specification.
|
...
|
An arbitrary number of parameters. The number and type of the
parameters are governed by the fmt string.
|
NULL
character pointer. A NULL
return
value indicates an error in processing. Retrieve the reason for the error using
PR_GetError
.
NULL
is at
the end of the buffer.
This function is identical to PR_snprintf
except that the output buffer is allocated
by the runtime rather than passed into the function. If the function is successful, the
returned buffer belongs to the caller. When it is no longer used, free it using
PR_smprintf_free
.
char* PR_sprintf_append (
char *last,
const char *fmt,
...);
NULL
character pointer. The result
should be treated as a new string. In case of error, returns NULL
.
last
, plus the result of the current transformation.
If no string is specified, the function allocates a new character buffer. The function
extends the buffer as needed, using standard heap allocators. If the value of last
is
not NULL
, the function reallocates a new buffer sufficient to hold the existing string
plus the result of the new translation, and deletes the passed string.
The buffer returned by the function belongs to the caller. When it is no longer used,
free it using PR_smprintf_free
.
PR_smprintf
.
void PR_smprintf_free (char *str);
str
|
A string buffer returned by a previous call to PR_smprintf .
|
PR_smprintf
or PR_sprintf_append
. If the
specified buffer was not allocated by one of these functions, the result is undefined.
PRUint32 PR_sxprintf (
PRStuffFunc f,
void *arg,
const char *fmt,
...);
0xffffffff
if the
transformation fails.
The stuff function may be called more than once for each call to PR_sxprintf
. Each
call should return the number of bytes actually accepted by the stuff function for
that particular call, or -1 if the function fails.
The stuff function must be supplied by the client, and must conform to the following signature:
typedef PRIntn (*PRStuffFunc)
(void *arg, const char *s, PRUint32 slen);
The stuff function has these parameters:
arg
|
A pointer to an object referenced by the caller of PR_sxprintf that
contains sufficient state for the stuff function to know where to put the
new transformed fragment.
|
s
|
A character buffer containing a transformed fragment that is to be added
to the state of the object referenced by arg .
|
slen
|
The length of the buffer s .
|
PRUint32 PR_fprintf (
struct PRFileDesc* fd,
const char *fmt,
...);
0xffffffff
if
the transformation fails. It is possible for some transformed bytes to be written to
the file before the function fails.
PR_Write
. The output function may be called multiple times.
va_list
forms of the output functions
described above. The functions are:
PR_vsnprintf
PR_vsmprintf
PR_vsprintf_append
PR_vsxprintf
PR_vfprintf
PRUint32 PR_vsnprintf (
char *out,
PRUint32 outlen,
const char *fmt,
va_list ap);
char* PR_vsmprintf (
const char *fmt,
va_list ap);
char* PR_vsprintf_append (
char *last,
const char *fmt,
va_list ap);
PRUint32 PR_vsxprintf (
PRStuffFunc f,
void *arg,
const char *fmt,
va_list ap);
PRUint32 PR_vfprintf (
struct PRFileDesc* fd,
const char *fmt,
va_list ap);
PR_sscanf
.
PRInt32 PR_sscanf (
const char *buf,
const char *fmt,
...);
This function behaves the same way as the sscanf()
function in the Standard C
Library (stdio.h
), with the following exceptions:
PR_sscanf
handles the NSPR integer and floating point types, such as
PRInt16
, PRInt32
, PRInt64
, and PRFloat64
,
PR_sscanf
has no multibyte character support.
Last Updated May 18, 2001