1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <fbl/string_buffer.h> 6 7 #include <stdio.h> 8 #include <string.h> 9 10 namespace fbl { 11 namespace internal { 12 StringBufferAppendPrintf(char * dest,size_t remaining,const char * format,va_list ap)13size_t StringBufferAppendPrintf(char* dest, size_t remaining, 14 const char* format, va_list ap) { 15 if (remaining == 0u) { 16 return 0u; 17 } 18 int count = vsnprintf(dest, remaining + 1u, format, ap); 19 if (count < 0) { 20 return 0u; 21 } 22 size_t length = static_cast<size_t>(count); 23 return length >= remaining ? remaining : length; 24 } 25 26 } // namespace internal 27 } // namespace fbl 28