2 * Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
9 #include "ppapi/native_client/src/untrusted/nacl_ppapi_util/string_buffer.h"
13 StringBuffer::StringBuffer() {
16 buffer_ = reinterpret_cast<char *>(malloc(nbytes_));
17 if (NULL == buffer_) {
18 perror("StringBuffer Ctor malloc");
24 void StringBuffer::DiscardOutput() {
29 StringBuffer::~StringBuffer() {
36 void StringBuffer::Printf(char const *fmt, ...) {
44 space = nbytes_ - insert_;
45 insert_pt = buffer_ + insert_;
47 written = vsnprintf(insert_pt, space, fmt, ap);
49 if (written < space) {
53 // insufficient space -- grow the buffer
54 new_buffer = reinterpret_cast<char *>(realloc(buffer_, 2 * nbytes_));
55 if (NULL == new_buffer) {
57 fprintf(stderr, "StringBufferPrintf: no memory\n");