2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Vic Lee
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
24 #include <freerdp/utils/memory.h>
25 #include <freerdp/utils/stream.h>
27 STREAM* stream_new(int size)
31 stream = xnew(STREAM);
37 size = size > 0 ? size : 0x400;
38 stream->data = (uint8*) xzalloc(size);
39 stream->p = stream->data;
47 void stream_free(STREAM* stream)
51 if (stream->data != NULL)
58 void stream_extend(STREAM* stream, int request_size)
64 pos = stream_get_pos(stream);
65 original_size = stream->size;
66 increased_size = (request_size > original_size ? request_size : original_size);
67 stream->size += increased_size;
69 if (original_size == 0)
70 stream->data = (uint8*) xmalloc(stream->size);
72 stream->data = (uint8*) xrealloc(stream->data, stream->size);
74 memset(stream->data + original_size, 0, increased_size);
75 stream_set_pos(stream, pos);