1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsprf.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef jsprf_h 1.11 +#define jsprf_h 1.12 + 1.13 +/* 1.14 +** API for PR printf like routines. Supports the following formats 1.15 +** %d - decimal 1.16 +** %u - unsigned decimal 1.17 +** %x - unsigned hex 1.18 +** %X - unsigned uppercase hex 1.19 +** %o - unsigned octal 1.20 +** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above 1.21 +** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above 1.22 +** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above 1.23 +** %s - ascii string 1.24 +** %hs - ucs2 string 1.25 +** %c - character 1.26 +** %p - pointer (deals with machine dependent pointer size) 1.27 +** %f - float 1.28 +** %g - float 1.29 +*/ 1.30 + 1.31 +#include <stdarg.h> 1.32 + 1.33 +#include "jstypes.h" 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 (uint32_t)-1 if an error occurs. 1.39 +*/ 1.40 +extern JS_PUBLIC_API(uint32_t) JS_snprintf(char *out, uint32_t outlen, const char *fmt, ...); 1.41 + 1.42 +/* 1.43 +** sprintf into a malloc'd buffer. Return a pointer to the malloc'd 1.44 +** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release 1.45 +** the memory returned. 1.46 +*/ 1.47 +extern JS_PUBLIC_API(char*) JS_smprintf(const char *fmt, ...); 1.48 + 1.49 +/* 1.50 +** Free the memory allocated, for the caller, by JS_smprintf 1.51 +*/ 1.52 +extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); 1.53 + 1.54 +/* 1.55 +** "append" sprintf into a malloc'd buffer. "last" is the last value of 1.56 +** the malloc'd buffer. sprintf will append data to the end of last, 1.57 +** growing it as necessary using realloc. If last is nullptr, JS_sprintf_append 1.58 +** will allocate the initial string. The return value is the new value of 1.59 +** last for subsequent calls, or nullptr if there is a malloc failure. 1.60 +*/ 1.61 +extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); 1.62 + 1.63 +/* 1.64 +** va_list forms of the above. 1.65 +*/ 1.66 +extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char *out, uint32_t outlen, const char *fmt, va_list ap); 1.67 +extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); 1.68 +extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); 1.69 + 1.70 +#endif /* jsprf_h */