5 #include "memory-stream.hh"
10 is_memory_stream (void *foo)
12 Memory_out_stream *cookie = (Memory_out_stream *) foo;
13 return dynamic_cast<Memory_out_stream *> (cookie);
17 lily_fopencookie (void *cookie,
18 char const * /* modes */,
19 lily_cookie_io_functions_t /* io_funcs */)
21 assert (is_memory_stream (cookie));
22 return (FILE *) cookie;
26 lily_cookie_fclose (void *file)
28 assert (is_memory_stream (file));
29 return Memory_out_stream::cleaner (file);
33 lily_cookie_fprintf (void *file, char const *format, ...)
35 assert (is_memory_stream (file));
37 va_start (ap, format);
39 static char buf[65536];
40 int i = vsnprintf (buf, sizeof (buf), format, ap);
41 if (i < 0 || (unsigned) i > sizeof (buf))
44 return Memory_out_stream::writer (file, buf, (unsigned)i);
48 lily_cookie_putc (int c, void *file)
50 assert (is_memory_stream (file));
53 return Memory_out_stream::writer (file, buf, 1);