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