1 |
/* |
/* |
2 |
stream.c - `Stream' object |
stream.c - `Stream' object |
3 |
Copyright (C) 2008 siliconforks.com |
Copyright (C) 2008, 2009, 2010 siliconforks.com |
4 |
|
|
5 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
6 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
76 |
} |
} |
77 |
|
|
78 |
void Stream_write_char(Stream * stream, char c) { |
void Stream_write_char(Stream * stream, char c) { |
79 |
Stream_write(stream, &c, 1); |
size_t stream_length = stream->length; |
80 |
|
if (stream_length == stream->capacity) { |
81 |
|
if (stream->capacity == SIZE_MAX) { |
82 |
|
fatal("out of memory"); |
83 |
|
} |
84 |
|
|
85 |
|
if (SIZE_MAX / 2 < stream->capacity) { |
86 |
|
stream->capacity = SIZE_MAX; |
87 |
|
} |
88 |
|
else { |
89 |
|
stream->capacity *= 2; |
90 |
|
} |
91 |
|
|
92 |
|
stream->data = xrealloc(stream->data, stream->capacity); |
93 |
|
} |
94 |
|
stream->data[stream_length] = c; |
95 |
|
stream->length = stream_length + 1; |
96 |
} |
} |
97 |
|
|
98 |
void Stream_printf(Stream * stream, const char * format, ...) { |
void Stream_printf(Stream * stream, const char * format, ...) { |