Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef jsprf_h |
michael@0 | 8 | #define jsprf_h |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | ** API for PR printf like routines. Supports the following formats |
michael@0 | 12 | ** %d - decimal |
michael@0 | 13 | ** %u - unsigned decimal |
michael@0 | 14 | ** %x - unsigned hex |
michael@0 | 15 | ** %X - unsigned uppercase hex |
michael@0 | 16 | ** %o - unsigned octal |
michael@0 | 17 | ** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above |
michael@0 | 18 | ** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above |
michael@0 | 19 | ** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above |
michael@0 | 20 | ** %s - ascii string |
michael@0 | 21 | ** %hs - ucs2 string |
michael@0 | 22 | ** %c - character |
michael@0 | 23 | ** %p - pointer (deals with machine dependent pointer size) |
michael@0 | 24 | ** %f - float |
michael@0 | 25 | ** %g - float |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | #include <stdarg.h> |
michael@0 | 29 | |
michael@0 | 30 | #include "jstypes.h" |
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 (uint32_t)-1 if an error occurs. |
michael@0 | 36 | */ |
michael@0 | 37 | extern JS_PUBLIC_API(uint32_t) JS_snprintf(char *out, uint32_t outlen, const char *fmt, ...); |
michael@0 | 38 | |
michael@0 | 39 | /* |
michael@0 | 40 | ** sprintf into a malloc'd buffer. Return a pointer to the malloc'd |
michael@0 | 41 | ** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release |
michael@0 | 42 | ** the memory returned. |
michael@0 | 43 | */ |
michael@0 | 44 | extern JS_PUBLIC_API(char*) JS_smprintf(const char *fmt, ...); |
michael@0 | 45 | |
michael@0 | 46 | /* |
michael@0 | 47 | ** Free the memory allocated, for the caller, by JS_smprintf |
michael@0 | 48 | */ |
michael@0 | 49 | extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); |
michael@0 | 50 | |
michael@0 | 51 | /* |
michael@0 | 52 | ** "append" sprintf into a malloc'd buffer. "last" is the last value of |
michael@0 | 53 | ** the malloc'd buffer. sprintf will append data to the end of last, |
michael@0 | 54 | ** growing it as necessary using realloc. If last is nullptr, JS_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 nullptr if there is a malloc failure. |
michael@0 | 57 | */ |
michael@0 | 58 | extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); |
michael@0 | 59 | |
michael@0 | 60 | /* |
michael@0 | 61 | ** va_list forms of the above. |
michael@0 | 62 | */ |
michael@0 | 63 | extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); |
michael@0 | 64 | extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); |
michael@0 | 65 | extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); |
michael@0 | 66 | |
michael@0 | 67 | #endif /* jsprf_h */ |