Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef prprf_h___ |
michael@0 | 7 | #define prprf_h___ |
michael@0 | 8 | |
michael@0 | 9 | /* |
michael@0 | 10 | ** API for PR printf like routines. Supports the following formats |
michael@0 | 11 | ** %d - decimal |
michael@0 | 12 | ** %u - unsigned decimal |
michael@0 | 13 | ** %x - unsigned hex |
michael@0 | 14 | ** %X - unsigned uppercase hex |
michael@0 | 15 | ** %o - unsigned octal |
michael@0 | 16 | ** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above |
michael@0 | 17 | ** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above |
michael@0 | 18 | ** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above |
michael@0 | 19 | ** %s - string |
michael@0 | 20 | ** %c - character |
michael@0 | 21 | ** %p - pointer (deals with machine dependent pointer size) |
michael@0 | 22 | ** %f - float |
michael@0 | 23 | ** %g - float |
michael@0 | 24 | */ |
michael@0 | 25 | #include "prtypes.h" |
michael@0 | 26 | #include "prio.h" |
michael@0 | 27 | #include <stdio.h> |
michael@0 | 28 | #include <stdarg.h> |
michael@0 | 29 | |
michael@0 | 30 | PR_BEGIN_EXTERN_C |
michael@0 | 31 | |
michael@0 | 32 | /* |
michael@0 | 33 | ** sprintf into a fixed size buffer. Guarantees that a NUL is at the end |
michael@0 | 34 | ** of the buffer. Returns the length of the written output, NOT including |
michael@0 | 35 | ** the NUL, or (PRUint32)-1 if an error occurs. |
michael@0 | 36 | */ |
michael@0 | 37 | NSPR_API(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...); |
michael@0 | 38 | |
michael@0 | 39 | /* |
michael@0 | 40 | ** sprintf into a PR_MALLOC'd buffer. Return a pointer to the malloc'd |
michael@0 | 41 | ** buffer on success, NULL on failure. Call "PR_smprintf_free" to release |
michael@0 | 42 | ** the memory returned. |
michael@0 | 43 | */ |
michael@0 | 44 | NSPR_API(char*) PR_smprintf(const char *fmt, ...); |
michael@0 | 45 | |
michael@0 | 46 | /* |
michael@0 | 47 | ** Free the memory allocated, for the caller, by PR_smprintf |
michael@0 | 48 | */ |
michael@0 | 49 | NSPR_API(void) PR_smprintf_free(char *mem); |
michael@0 | 50 | |
michael@0 | 51 | /* |
michael@0 | 52 | ** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of |
michael@0 | 53 | ** the PR_MALLOC'd buffer. sprintf will append data to the end of last, |
michael@0 | 54 | ** growing it as necessary using realloc. If last is NULL, PR_sprintf_append |
michael@0 | 55 | ** will allocate the initial string. The return value is the new value of |
michael@0 | 56 | ** last for subsequent calls, or NULL if there is a malloc failure. |
michael@0 | 57 | */ |
michael@0 | 58 | NSPR_API(char*) PR_sprintf_append(char *last, const char *fmt, ...); |
michael@0 | 59 | |
michael@0 | 60 | /* |
michael@0 | 61 | ** sprintf into a function. The function "f" is called with a string to |
michael@0 | 62 | ** place into the output. "arg" is an opaque pointer used by the stuff |
michael@0 | 63 | ** function to hold any state needed to do the storage of the output |
michael@0 | 64 | ** data. The return value is a count of the number of characters fed to |
michael@0 | 65 | ** the stuff function, or (PRUint32)-1 if an error occurs. |
michael@0 | 66 | */ |
michael@0 | 67 | typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen); |
michael@0 | 68 | |
michael@0 | 69 | NSPR_API(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...); |
michael@0 | 70 | |
michael@0 | 71 | /* |
michael@0 | 72 | ** fprintf to a PRFileDesc |
michael@0 | 73 | */ |
michael@0 | 74 | NSPR_API(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...); |
michael@0 | 75 | |
michael@0 | 76 | /* |
michael@0 | 77 | ** va_list forms of the above. |
michael@0 | 78 | */ |
michael@0 | 79 | NSPR_API(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap); |
michael@0 | 80 | NSPR_API(char*) PR_vsmprintf(const char *fmt, va_list ap); |
michael@0 | 81 | NSPR_API(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap); |
michael@0 | 82 | NSPR_API(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap); |
michael@0 | 83 | NSPR_API(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list ap); |
michael@0 | 84 | |
michael@0 | 85 | /* |
michael@0 | 86 | *************************************************************************** |
michael@0 | 87 | ** FUNCTION: PR_sscanf |
michael@0 | 88 | ** DESCRIPTION: |
michael@0 | 89 | ** PR_sscanf() scans the input character string, performs data |
michael@0 | 90 | ** conversions, and stores the converted values in the data objects |
michael@0 | 91 | ** pointed to by its arguments according to the format control |
michael@0 | 92 | ** string. |
michael@0 | 93 | ** |
michael@0 | 94 | ** PR_sscanf() behaves the same way as the sscanf() function in the |
michael@0 | 95 | ** Standard C Library (stdio.h), with the following exceptions: |
michael@0 | 96 | ** - PR_sscanf() handles the NSPR integer and floating point types, |
michael@0 | 97 | ** such as PRInt16, PRInt32, PRInt64, and PRFloat64, whereas |
michael@0 | 98 | ** sscanf() handles the standard C types like short, int, long, |
michael@0 | 99 | ** and double. |
michael@0 | 100 | ** - PR_sscanf() has no multibyte character support, while sscanf() |
michael@0 | 101 | ** does. |
michael@0 | 102 | ** INPUTS: |
michael@0 | 103 | ** const char *buf |
michael@0 | 104 | ** a character string holding the input to scan |
michael@0 | 105 | ** const char *fmt |
michael@0 | 106 | ** the format control string for the conversions |
michael@0 | 107 | ** ... |
michael@0 | 108 | ** variable number of arguments, each of them is a pointer to |
michael@0 | 109 | ** a data object in which the converted value will be stored |
michael@0 | 110 | ** OUTPUTS: none |
michael@0 | 111 | ** RETURNS: PRInt32 |
michael@0 | 112 | ** The number of values converted and stored. |
michael@0 | 113 | ** RESTRICTIONS: |
michael@0 | 114 | ** Multibyte characters in 'buf' or 'fmt' are not allowed. |
michael@0 | 115 | *************************************************************************** |
michael@0 | 116 | */ |
michael@0 | 117 | |
michael@0 | 118 | NSPR_API(PRInt32) PR_sscanf(const char *buf, const char *fmt, ...); |
michael@0 | 119 | |
michael@0 | 120 | PR_END_EXTERN_C |
michael@0 | 121 | |
michael@0 | 122 | #endif /* prprf_h___ */ |