Update THANKS.
[lilypond.git] / flower / file-cookie.cc
blob49b5518f362264b6740476336b55ca6036a2eba3
2 #include <cassert>
3 #include <cstdio>
4 using namespace std;
6 #include "memory-stream.hh"
8 extern "C" {
10 bool
11 is_memory_stream (void *foo)
13 Memory_out_stream *cookie = (Memory_out_stream *) foo;
14 return dynamic_cast<Memory_out_stream *> (cookie);
17 void *
18 lily_fopencookie (void *cookie, char const *modes,
19 lily_cookie_io_functions_t io_funcs)
21 (void) cookie;
22 (void) modes;
23 (void) io_funcs;
24 assert (is_memory_stream (cookie));
25 return (FILE *) cookie;
28 int
29 lily_cookie_fclose (void *file)
31 assert (is_memory_stream (file));
32 return Memory_out_stream::cleaner (file);
35 int
36 lily_cookie_fprintf (void *file, char const *format, ...)
38 assert (is_memory_stream (file));
39 va_list ap;
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))
45 assert (false);
46 va_end (ap);
47 return Memory_out_stream::writer (file, buf, i);
50 int
51 lily_cookie_putc (int c, void *file)
53 assert (is_memory_stream (file));
54 char buf[1];
55 buf[0] = (char) c;
56 return Memory_out_stream::writer (file, buf, 1);
58 } /* extern C */