2 * Copyright (C) 2005 Richard Kettlewell
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <vdecommon.h>
30 /* BSD-compatible implementation of open_memstream */
41 static int memstream_writefn(void *u
, const char *buffer
, int bytes
) {
42 struct memstream
*m
= u
;
43 size_t needed
= m
->size
+ bytes
+ 1;
48 if(needed
> m
->space
) {
49 newspace
= m
->space
? m
->space
: 32;
50 while(newspace
&& newspace
< needed
)
56 if(!(newbuffer
= realloc(m
->buffer
, newspace
)))
58 m
->buffer
= newbuffer
;
61 memcpy(m
->buffer
+ m
->size
, buffer
, bytes
);
63 m
->buffer
[m
->size
] = 0;
66 *m
->sizeloc
= m
->size
;
70 FILE *open_memstream(char **ptr
, size_t *sizeloc
) {
73 if(!(m
= malloc(sizeof *m
))) return 0;