Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / native_client_sdk / src / libraries / error_handling / string_stream.c
blobb21ab2155badcf078d3a481e84c2f7bffad9e56f
1 /* Copyright (c) 2013 The Chromium 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. */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
9 #include "error_handling/string_stream.h"
10 void ssinit(sstream_t* stream) {
11 stream->data = NULL;
12 stream->length = 0;
15 void ssfree(sstream_t* stream) {
16 free(stream->data);
17 stream->data = 0;
18 stream->length = 0;
21 int ssvprintf(sstream_t* stream, const char* format, va_list args) {
22 va_list hold;
23 int len;
24 char* outstr;
26 va_copy(hold, args);
27 len = vsnprintf(NULL, 0, format, args);
29 outstr = malloc(stream->length + len + 1);
30 if (stream->data) {
31 memcpy(outstr, stream->data, stream->length);
32 free(stream->data);
35 stream->data = outstr;
36 vsprintf(&stream->data[stream->length], format, hold);
37 stream->length += len;
39 return len;
42 int ssprintf(sstream_t* stream, const char* format, ...) {
43 int out;
44 va_list args;
45 va_start(args, format);
46 out = ssvprintf(stream, format, args);
47 va_end(args);
49 return out;