nsprpub/pr/include/prprf.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/include/prprf.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,122 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef prprf_h___
    1.10 +#define prprf_h___
    1.11 +
    1.12 +/*
    1.13 +** API for PR printf like routines. Supports the following formats
    1.14 +**	%d - decimal
    1.15 +**	%u - unsigned decimal
    1.16 +**	%x - unsigned hex
    1.17 +**	%X - unsigned uppercase hex
    1.18 +**	%o - unsigned octal
    1.19 +**	%hd, %hu, %hx, %hX, %ho - 16-bit versions of above
    1.20 +**	%ld, %lu, %lx, %lX, %lo - 32-bit versions of above
    1.21 +**	%lld, %llu, %llx, %llX, %llo - 64 bit versions of above
    1.22 +**	%s - string
    1.23 +**	%c - character
    1.24 +**	%p - pointer (deals with machine dependent pointer size)
    1.25 +**	%f - float
    1.26 +**	%g - float
    1.27 +*/
    1.28 +#include "prtypes.h"
    1.29 +#include "prio.h"
    1.30 +#include <stdio.h>
    1.31 +#include <stdarg.h>
    1.32 +
    1.33 +PR_BEGIN_EXTERN_C
    1.34 +
    1.35 +/*
    1.36 +** sprintf into a fixed size buffer. Guarantees that a NUL is at the end
    1.37 +** of the buffer. Returns the length of the written output, NOT including
    1.38 +** the NUL, or (PRUint32)-1 if an error occurs.
    1.39 +*/
    1.40 +NSPR_API(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...);
    1.41 +
    1.42 +/*
    1.43 +** sprintf into a PR_MALLOC'd buffer. Return a pointer to the malloc'd
    1.44 +** buffer on success, NULL on failure. Call "PR_smprintf_free" to release
    1.45 +** the memory returned.
    1.46 +*/
    1.47 +NSPR_API(char*) PR_smprintf(const char *fmt, ...);
    1.48 +
    1.49 +/*
    1.50 +** Free the memory allocated, for the caller, by PR_smprintf
    1.51 +*/
    1.52 +NSPR_API(void) PR_smprintf_free(char *mem);
    1.53 +
    1.54 +/*
    1.55 +** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of
    1.56 +** the PR_MALLOC'd buffer. sprintf will append data to the end of last,
    1.57 +** growing it as necessary using realloc. If last is NULL, PR_sprintf_append
    1.58 +** will allocate the initial string. The return value is the new value of
    1.59 +** last for subsequent calls, or NULL if there is a malloc failure.
    1.60 +*/
    1.61 +NSPR_API(char*) PR_sprintf_append(char *last, const char *fmt, ...);
    1.62 +
    1.63 +/*
    1.64 +** sprintf into a function. The function "f" is called with a string to
    1.65 +** place into the output. "arg" is an opaque pointer used by the stuff
    1.66 +** function to hold any state needed to do the storage of the output
    1.67 +** data. The return value is a count of the number of characters fed to
    1.68 +** the stuff function, or (PRUint32)-1 if an error occurs.
    1.69 +*/
    1.70 +typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen);
    1.71 +
    1.72 +NSPR_API(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...);
    1.73 +
    1.74 +/*
    1.75 +** fprintf to a PRFileDesc
    1.76 +*/
    1.77 +NSPR_API(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...);
    1.78 +
    1.79 +/*
    1.80 +** va_list forms of the above.
    1.81 +*/
    1.82 +NSPR_API(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap);
    1.83 +NSPR_API(char*) PR_vsmprintf(const char *fmt, va_list ap);
    1.84 +NSPR_API(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap);
    1.85 +NSPR_API(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap);
    1.86 +NSPR_API(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list ap);
    1.87 +
    1.88 +/*
    1.89 +***************************************************************************
    1.90 +** FUNCTION: PR_sscanf
    1.91 +** DESCRIPTION:
    1.92 +**     PR_sscanf() scans the input character string, performs data
    1.93 +**     conversions, and stores the converted values in the data objects
    1.94 +**     pointed to by its arguments according to the format control
    1.95 +**     string.
    1.96 +**
    1.97 +**     PR_sscanf() behaves the same way as the sscanf() function in the
    1.98 +**     Standard C Library (stdio.h), with the following exceptions:
    1.99 +**     - PR_sscanf() handles the NSPR integer and floating point types,
   1.100 +**       such as PRInt16, PRInt32, PRInt64, and PRFloat64, whereas
   1.101 +**       sscanf() handles the standard C types like short, int, long,
   1.102 +**       and double.
   1.103 +**     - PR_sscanf() has no multibyte character support, while sscanf()
   1.104 +**       does.
   1.105 +** INPUTS:
   1.106 +**     const char *buf
   1.107 +**         a character string holding the input to scan
   1.108 +**     const char *fmt
   1.109 +**         the format control string for the conversions
   1.110 +**     ...
   1.111 +**         variable number of arguments, each of them is a pointer to
   1.112 +**         a data object in which the converted value will be stored
   1.113 +** OUTPUTS: none
   1.114 +** RETURNS: PRInt32
   1.115 +**     The number of values converted and stored.
   1.116 +** RESTRICTIONS:
   1.117 +**    Multibyte characters in 'buf' or 'fmt' are not allowed.
   1.118 +***************************************************************************
   1.119 +*/
   1.120 +
   1.121 +NSPR_API(PRInt32) PR_sscanf(const char *buf, const char *fmt, ...);
   1.122 +
   1.123 +PR_END_EXTERN_C
   1.124 +
   1.125 +#endif /* prprf_h___ */

mercurial