2 simple-file-storage.cc -- implement Simple_file_storage
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 #include "simple-file-storage.hh"
21 Simple_file_storage::load_stdin ()
27 while ((c
= fgetc (stdin
)) != EOF
)
29 len_i_
= ch_arr
.size ();
30 data_p_
= ch_arr
.remove_array_p ();
34 Simple_file_storage::load_file (String s
)
37 let's hope that "b" opens anything binary, and does not apply
40 FILE * f
= fopen (s
.ch_C (), "rb");
44 warning (_f ("Can't open file: `%s'", s
));
48 int ret
= fseek (f
, 0, SEEK_END
);
51 data_p_
= new char[len_i_
+1];
53 ret
= fread (data_p_
, sizeof (char), len_i_
, f
);
56 warning (_f ("Huh? Got %d, expected %d characters", ret
, len_i_
));
62 Stupid but foolproof way of opening files.
65 Should check IO status
67 This is of course a build it yourself version of mmap, so we should
68 have been using that..., but this is simple & portable
72 Simple_file_storage::Simple_file_storage (String s
)
77 if (!s
.length_i () || (s
== "-"))
84 Simple_file_storage::ch_C () const
90 Simple_file_storage::length_i () const
96 Simple_file_storage::~Simple_file_storage ()