2013-04-16 20:47:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2013-06-20 00:59:46 +00:00
|
|
|
#ifndef jsprf_h
|
|
|
|
#define jsprf_h
|
1998-10-14 10:22:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** API for PR printf like routines. Supports the following formats
|
2004-12-09 01:32:19 +00:00
|
|
|
** %d - decimal
|
|
|
|
** %u - unsigned decimal
|
|
|
|
** %x - unsigned hex
|
|
|
|
** %X - unsigned uppercase hex
|
|
|
|
** %o - unsigned octal
|
2016-10-11 18:44:40 +00:00
|
|
|
** %hd, %hu, %hx, %hX, %ho - "short" versions of above
|
|
|
|
** %ld, %lu, %lx, %lX, %lo - "long" versions of above
|
|
|
|
** %lld, %llu, %llx, %llX, %llo - "long long" versions of above
|
|
|
|
** %zd, %zo, %zu, %zx, %zX - size_t versions of above
|
|
|
|
** %Id, %Io, %Iu, %Ix, %IX - size_t versions of above (for Windows compat)
|
|
|
|
** You should use PRI*SIZE macros instead
|
|
|
|
** %s - string
|
2004-12-09 01:32:19 +00:00
|
|
|
** %c - character
|
|
|
|
** %p - pointer (deals with machine dependent pointer size)
|
|
|
|
** %f - float
|
|
|
|
** %g - float
|
1998-10-14 10:22:38 +00:00
|
|
|
*/
|
2013-07-24 00:34:50 +00:00
|
|
|
|
2015-12-12 17:41:00 +00:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
|
|
|
#include "mozilla/SizePrintfMacros.h"
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
#include <stdarg.h>
|
2013-07-24 00:34:50 +00:00
|
|
|
|
|
|
|
#include "jstypes.h"
|
1998-10-14 10:22:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** sprintf into a malloc'd buffer. Return a pointer to the malloc'd
|
2013-10-07 16:44:00 +00:00
|
|
|
** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release
|
1998-10-14 10:22:38 +00:00
|
|
|
** the memory returned.
|
|
|
|
*/
|
2016-10-11 18:44:40 +00:00
|
|
|
extern JS_PUBLIC_API(char*) JS_smprintf(const char* fmt, ...)
|
|
|
|
MOZ_FORMAT_PRINTF(1, 2);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Free the memory allocated, for the caller, by JS_smprintf
|
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
extern JS_PUBLIC_API(void) JS_smprintf_free(char* mem);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** "append" sprintf into a malloc'd buffer. "last" is the last value of
|
|
|
|
** the malloc'd buffer. sprintf will append data to the end of last,
|
2013-10-07 16:44:00 +00:00
|
|
|
** growing it as necessary using realloc. If last is nullptr, JS_sprintf_append
|
1998-10-14 10:22:38 +00:00
|
|
|
** will allocate the initial string. The return value is the new value of
|
2013-10-07 16:44:00 +00:00
|
|
|
** last for subsequent calls, or nullptr if there is a malloc failure.
|
1998-10-14 10:22:38 +00:00
|
|
|
*/
|
2016-10-11 18:44:40 +00:00
|
|
|
extern JS_PUBLIC_API(char*) JS_sprintf_append(char* last, const char* fmt, ...)
|
|
|
|
MOZ_FORMAT_PRINTF(2, 3);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** va_list forms of the above.
|
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
extern JS_PUBLIC_API(char*) JS_vsmprintf(const char* fmt, va_list ap);
|
|
|
|
extern JS_PUBLIC_API(char*) JS_vsprintf_append(char* last, const char* fmt, va_list ap);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2013-06-20 00:59:46 +00:00
|
|
|
#endif /* jsprf_h */
|