xpcom/glue/nsTextFormatter.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  * This code was copied from xpcom/ds/nsTextFormatter r1.3
     8  *           Memory model and Frozen linkage changes only.
     9  *                           -- Prasad <prasad@medhas.org>
    10  */
    12 #ifndef nsTextFormatter_h___
    13 #define nsTextFormatter_h___
    15 /*
    16  ** API for PR printf like routines. Supports the following formats
    17  **	%d - decimal
    18  **	%u - unsigned decimal
    19  **	%x - unsigned hex
    20  **	%X - unsigned uppercase hex
    21  **	%o - unsigned octal
    22  **	%hd, %hu, %hx, %hX, %ho - 16-bit versions of above
    23  **	%ld, %lu, %lx, %lX, %lo - 32-bit versions of above
    24  **	%lld, %llu, %llx, %llX, %llo - 64 bit versions of above
    25  **	%s - utf8 string
    26  **	%S - char16_t string
    27  **	%c - character
    28  **	%p - pointer (deals with machine dependent pointer size)
    29  **	%f - float
    30  **	%g - float
    31  */
    32 #include "prio.h"
    33 #include <stdio.h>
    34 #include <stdarg.h>
    35 #include "nscore.h"
    36 #include "nsStringGlue.h"
    38 #ifdef XPCOM_GLUE
    39 #error "nsTextFormatter is not available in the standalone glue due to NSPR dependencies."
    40 #endif
    42 class NS_COM_GLUE nsTextFormatter {
    44   public:
    46     /*
    47      * sprintf into a fixed size buffer. Guarantees that the buffer is null
    48      * terminated. Returns the length of the written output, NOT including the
    49      * null terminator, or (uint32_t)-1 if an error occurs.
    50      */
    51     static uint32_t snprintf(char16_t *out, uint32_t outlen, const char16_t *fmt, ...);
    53     /*
    54      * sprintf into a nsMemory::Alloc'd buffer. Return a pointer to 
    55      * buffer on success, nullptr on failure. 
    56      */
    57     static char16_t* smprintf(const char16_t *fmt, ...);
    59     static uint32_t ssprintf(nsAString& out, const char16_t* fmt, ...);
    61     /*
    62      * va_list forms of the above.
    63      */
    64     static uint32_t vsnprintf(char16_t *out, uint32_t outlen, const char16_t *fmt, va_list ap);
    65     static char16_t* vsmprintf(const char16_t *fmt, va_list ap);
    66     static uint32_t vssprintf(nsAString& out, const char16_t *fmt, va_list ap);
    68     /*
    69      * Free the memory allocated, for the caller, by smprintf.
    70      * -- Deprecated --
    71      * Callers can substitute calling smprintf_free with nsMemory::Free
    72      */
    73     static void smprintf_free(char16_t *mem);
    75 };
    77 #endif /* nsTextFormatter_h___ */

mercurial