tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FdPrintf.h (1804B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 
      7 #ifndef __FdPrintf_h__
      8 #define __FdPrintf_h__
      9 
     10 #include <cstdarg>
     11 
     12 #ifdef _WIN32
     13 typedef void* platform_handle_t;
     14 #else
     15 typedef int platform_handle_t;
     16 #endif
     17 
     18 /*
     19 * We can't use libc's (f)printf because it would reenter in replace_malloc,
     20 * So use a custom and simplified version.  Only %p, %zu, %s and %% are
     21 * supported, %zu, %s, support width specifiers.
     22 */
     23 int VSNPrintf(char* aBuf, size_t aSize, const char* aFormat, va_list aArgs)
     24 #ifdef __GNUC__
     25    __attribute__((format(printf, 3, 0)))
     26 #endif
     27    ;
     28 
     29 int SNPrintf(char* aBuf, size_t aSize, const char* aFormat, ...)
     30 #ifdef __GNUC__
     31    __attribute__((format(printf, 3, 4)))
     32 #endif
     33    ;
     34 
     35 /*
     36 * /!\ These functions use a fixed-size internal buffer. The caller is
     37 * expected to not use a format string that may overflow.
     38 * The aFd argument is a file descriptor on UNIX and a native win32 file
     39 * handle on Windows (from CreateFile). We can't use the windows POSIX
     40 * APIs is that they don't support O_APPEND in a multi-process-safe way,
     41 * while CreateFile does.
     42 */
     43 void VFdPrintf(platform_handle_t aFd, const char* aFormat, va_list aArgs)
     44 #ifdef __GNUC__
     45    __attribute__((format(printf, 2, 0)))
     46 #endif
     47    ;
     48 
     49 void FdPrintf(platform_handle_t aFd, const char* aFormat, ...)
     50 #ifdef __GNUC__
     51    __attribute__((format(printf, 2, 3)))
     52 #endif
     53    ;
     54 
     55 // Write buffer contents without formatting (eg for use with SNPrintf).
     56 void FdPuts(platform_handle_t aFd, const char* aBuf, size_t aLen);
     57 
     58 #endif /* __FdPrintf_h__ */