6 #include "memory-stream.hh"
11 is_memory_stream (void *foo)
13 Memory_out_stream *cookie = (Memory_out_stream *) foo;
14 return dynamic_cast<Memory_out_stream *> (cookie);
18 lily_fopencookie (void *cookie,
19 char const * /* modes */,
20 lily_cookie_io_functions_t /* io_funcs */)
22 assert (is_memory_stream (cookie));
23 return (FILE *) cookie;
27 lily_cookie_fclose (void *file)
29 assert (is_memory_stream (file));
30 return Memory_out_stream::cleaner (file);
34 lily_cookie_fprintf (void *file, char const *format, ...)
36 assert (is_memory_stream (file));
38 va_start (ap, format);
40 static char buf[65536];
41 int i = vsnprintf (buf, sizeof (buf), format, ap);
42 if (i == -1 || (unsigned) i > sizeof (buf))
45 return Memory_out_stream::writer (file, buf, i);
49 lily_cookie_putc (int c, void *file)
51 assert (is_memory_stream (file));
54 return Memory_out_stream::writer (file, buf, 1);