]> git.donarmstrong.com Git - lilypond.git/blob - flower/file-cookie.cc
* flower/memory-stream.cc (Memory_out_stream): remove fopencookie support.
[lilypond.git] / flower / file-cookie.cc
1
2 #include <assert.h>
3 #include <cstdio>
4
5 #include "memory-stream.hh"
6
7 extern "C" {
8
9   static bool
10   is_memory_stream (void *foo)
11   {
12     Memory_out_stream *cookie = (Memory_out_stream *) foo;
13     return dynamic_cast<Memory_out_stream *> (cookie);
14   }
15
16   void *
17   lily_fopencookie (void *cookie, char const *modes,
18                     lily_cookie_io_functions_t io_funcs)
19   {
20     (void) cookie;
21     (void) modes;
22     (void) io_funcs;
23     assert (is_memory_stream (cookie));
24     return (FILE *) cookie;
25   }
26
27   int
28   lily_cookie_fclose (void *file)
29   {
30     assert (is_memory_stream (file));
31     return Memory_out_stream::cleaner (file);
32   }
33
34   int
35   lily_cookie_fprintf (void *file, char const *format, ...)
36   {
37     assert (is_memory_stream (file));
38     va_list ap;
39     va_start (ap, format);
40
41     static char buf[65536];
42     int i = vsnprintf (buf, sizeof (buf), format, ap);
43     if (i == -1 || (unsigned) i > sizeof (buf))
44       assert (false);
45     va_end (ap);
46     return Memory_out_stream::writer (file, buf, i);
47   }
48
49   int
50   lily_cookie_putc (int c, void *file)
51   {
52     assert (is_memory_stream (file));
53     char buf[1];
54     buf[0] = (char) c;
55     return Memory_out_stream::writer (file, buf, 1);
56   }
57
58 } /* extern C */