1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_ALLOC_BASE_STRINGS_STRINGPRINTF_H_ 6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_ALLOC_BASE_STRINGS_STRINGPRINTF_H_ 7 8 #include <stdarg.h> // va_list 9 10 #include <string> 11 12 #include "build/build_config.h" 13 #include "partition_alloc/partition_alloc_base/compiler_specific.h" 14 #include "partition_alloc/partition_alloc_base/component_export.h" 15 16 namespace partition_alloc::internal::base { 17 18 // Since Only SystemErrorCodeToString and partition_alloc_perftests use 19 // StringPrintf, make StringPrintf not to support too long results. 20 // Instead, define max result length and truncate such results. 21 static constexpr size_t kMaxLengthOfTruncatingStringPrintfResult = 255U; 22 23 // Return a C++ string given printf-like input. 24 [[nodiscard]] PA_COMPONENT_EXPORT(PARTITION_ALLOC_BASE) std::string 25 TruncatingStringPrintf(const char* format, ...) PA_PRINTF_FORMAT(1, 2); 26 27 } // namespace partition_alloc::internal::base 28 29 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_ALLOC_BASE_STRINGS_STRINGPRINTF_H_ 30