blob: abcfdfa9af01d84385ce450362e76da628819d40 [file] [log] [blame]
Ethan Nicholas842d31b2019-01-22 10:59:11 -05001/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/sksl/SkSLOutputStream.h"
Ethan Nicholas842d31b2019-01-22 10:59:11 -05009
10namespace SkSL {
11
12void OutputStream::writeString(String s) {
13 this->write(s.c_str(), s.size());
14}
15
16void OutputStream::printf(const char format[], ...) {
17 va_list args;
18 va_start(args, format);
19 this->appendVAList(format, args);
20 va_end(args);
21}
22
23void OutputStream::appendVAList(const char format[], va_list args) {
24 char buffer[kBufferSize];
Ethan Nicholasc18bb512020-07-28 14:46:53 -040025 va_list copy;
26 va_copy(copy, args);
Ethan Nicholas842d31b2019-01-22 10:59:11 -050027 int length = vsnprintf(buffer, kBufferSize, format, args);
Ethan Nicholasc18bb512020-07-28 14:46:53 -040028 if (length > (int) kBufferSize) {
29 std::unique_ptr<char[]> bigBuffer(new char[length + 1]);
30 vsnprintf(bigBuffer.get(), length + 1, format, copy);
31 this->write(bigBuffer.get(), length);
32 } else {
33 this->write(buffer, length);
34 }
Ethan Nicholas842d31b2019-01-22 10:59:11 -050035}
36
37}