andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #ifndef prprf_h___ andre@0: #define prprf_h___ andre@0: andre@0: /* andre@0: ** API for PR printf like routines. Supports the following formats andre@0: ** %d - decimal andre@0: ** %u - unsigned decimal andre@0: ** %x - unsigned hex andre@0: ** %X - unsigned uppercase hex andre@0: ** %o - unsigned octal andre@0: ** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above andre@0: ** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above andre@0: ** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above andre@0: ** %s - string andre@0: ** %c - character andre@0: ** %p - pointer (deals with machine dependent pointer size) andre@0: ** %f - float andre@0: ** %g - float andre@0: */ andre@0: #include "prtypes.h" andre@0: #include "prio.h" andre@0: #include andre@0: #include andre@0: andre@0: PR_BEGIN_EXTERN_C andre@0: andre@0: /* andre@0: ** sprintf into a fixed size buffer. Guarantees that a NUL is at the end andre@0: ** of the buffer. Returns the length of the written output, NOT including andre@0: ** the NUL, or (PRUint32)-1 if an error occurs. andre@0: */ andre@0: NSPR_API(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...); andre@0: andre@0: /* andre@0: ** sprintf into a PR_MALLOC'd buffer. Return a pointer to the malloc'd andre@0: ** buffer on success, NULL on failure. Call "PR_smprintf_free" to release andre@0: ** the memory returned. andre@0: */ andre@0: NSPR_API(char*) PR_smprintf(const char *fmt, ...); andre@0: andre@0: /* andre@0: ** Free the memory allocated, for the caller, by PR_smprintf andre@0: */ andre@0: NSPR_API(void) PR_smprintf_free(char *mem); andre@0: andre@0: /* andre@0: ** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of andre@0: ** the PR_MALLOC'd buffer. sprintf will append data to the end of last, andre@0: ** growing it as necessary using realloc. If last is NULL, PR_sprintf_append andre@0: ** will allocate the initial string. The return value is the new value of andre@0: ** last for subsequent calls, or NULL if there is a malloc failure. andre@0: */ andre@0: NSPR_API(char*) PR_sprintf_append(char *last, const char *fmt, ...); andre@0: andre@0: /* andre@0: ** sprintf into a function. The function "f" is called with a string to andre@0: ** place into the output. "arg" is an opaque pointer used by the stuff andre@0: ** function to hold any state needed to do the storage of the output andre@0: ** data. The return value is a count of the number of characters fed to andre@0: ** the stuff function, or (PRUint32)-1 if an error occurs. andre@0: */ andre@0: typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen); andre@0: andre@0: NSPR_API(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...); andre@0: andre@0: /* andre@0: ** fprintf to a PRFileDesc andre@0: */ andre@0: NSPR_API(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...); andre@0: andre@0: /* andre@0: ** va_list forms of the above. andre@0: */ andre@0: NSPR_API(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap); andre@0: NSPR_API(char*) PR_vsmprintf(const char *fmt, va_list ap); andre@0: NSPR_API(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap); andre@0: NSPR_API(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap); andre@0: NSPR_API(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list ap); andre@0: andre@0: /* andre@0: *************************************************************************** andre@0: ** FUNCTION: PR_sscanf andre@0: ** DESCRIPTION: andre@0: ** PR_sscanf() scans the input character string, performs data andre@0: ** conversions, and stores the converted values in the data objects andre@0: ** pointed to by its arguments according to the format control andre@0: ** string. andre@0: ** andre@0: ** PR_sscanf() behaves the same way as the sscanf() function in the andre@0: ** Standard C Library (stdio.h), with the following exceptions: andre@0: ** - PR_sscanf() handles the NSPR integer and floating point types, andre@0: ** such as PRInt16, PRInt32, PRInt64, and PRFloat64, whereas andre@0: ** sscanf() handles the standard C types like short, int, long, andre@0: ** and double. andre@0: ** - PR_sscanf() has no multibyte character support, while sscanf() andre@0: ** does. andre@0: ** INPUTS: andre@0: ** const char *buf andre@0: ** a character string holding the input to scan andre@0: ** const char *fmt andre@0: ** the format control string for the conversions andre@0: ** ... andre@0: ** variable number of arguments, each of them is a pointer to andre@0: ** a data object in which the converted value will be stored andre@0: ** OUTPUTS: none andre@0: ** RETURNS: PRInt32 andre@0: ** The number of values converted and stored. andre@0: ** RESTRICTIONS: andre@0: ** Multibyte characters in 'buf' or 'fmt' are not allowed. andre@0: *************************************************************************** andre@0: */ andre@0: andre@0: NSPR_API(PRInt32) PR_sscanf(const char *buf, const char *fmt, ...); andre@0: andre@0: PR_END_EXTERN_C andre@0: andre@0: #endif /* prprf_h___ */