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, char const *modes,
19 lily_cookie_io_functions_t io_funcs)
24 assert (is_memory_stream (cookie));
25 return (FILE *) cookie;
29 lily_cookie_fclose (void *file)
31 assert (is_memory_stream (file));
32 return Memory_out_stream::cleaner (file);
36 lily_cookie_fprintf (void *file, char const *format, ...)
38 assert (is_memory_stream (file));
40 va_start (ap, format);
42 static char buf[65536];
43 int i = vsnprintf (buf, sizeof (buf), format, ap);
44 if (i == -1 || (unsigned) i > sizeof (buf))
47 return Memory_out_stream::writer (file, buf, i);
51 lily_cookie_putc (int c, void *file)
53 assert (is_memory_stream (file));
56 return Memory_out_stream::writer (file, buf, 1);