this repo has no description
at trunk 33 lines 881 B view raw
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2#include <climits> 3#include <cstdarg> 4#include <cstdio> 5 6#include "cpython-func.h" 7 8#include "globals.h" 9#include "utils.h" 10 11namespace py { 12 13PY_EXPORT int PyOS_snprintf(char* str, size_t size, const char* format, ...) { 14 va_list va; 15 va_start(va, format); 16 int result = PyOS_vsnprintf(str, size, format, va); 17 va_end(va); 18 return result; 19} 20 21PY_EXPORT int PyOS_vsnprintf(char* str, size_t size, const char* format, 22 va_list va) { 23 DCHECK(str != nullptr, "string to write to cannot be null"); 24 DCHECK(size > 0, "number of characters to write must be positive"); 25 DCHECK(format != nullptr, "format string cannot be null"); 26 if (size > (INT_MAX - 1)) { 27 str[size - 1] = '\0'; 28 return -666; 29 } 30 return std::vsnprintf(str, size, format, va); 31} 32 33} // namespace py