jsprf.h 2.3 KB

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