2 simple-file-storage.cc -- implement Simple_file_storage
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
11 #include "simple-file-storage.hh"
17 Simple_file_storage::load_stdin ()
24 while ((c = fgetc (stdin)) != EOF)
26 len_i_ = ch_arr.size ();
27 data_p_ = ch_arr.remove_array_p ();
31 Simple_file_storage::load_file (String s)
34 let's hope that "b" opens anything binary, and does not apply
37 FILE * f = fopen (s.ch_C (), "rb");
41 warning (_ ("can't open file `") + s + "'");
45 int ret = fseek (f, 0, SEEK_END);
48 data_p_ = new char[len_i_+1];
50 ret = fread (data_p_, sizeof (char), len_i_, f);
53 warning (_ ("Huh? got ") + String (ret) + _ (", expected ")
54 + String (len_i_) + _ (" characters"));
60 Stupid but foolproof way of opening files.
63 Should check IO status
65 This is of course a build it yourself version of mmap, so we should
66 have been using that... (see Mapped_file_storage) But we noticed
67 some problems with this (unexplained lexer crashes)
69 [Some versions later] The crashes aren't caused by the mmap
70 code. But no reason to take it out, is there? mmap ()
74 Simple_file_storage::Simple_file_storage (String s)
86 Simple_file_storage::ch_C () const
92 Simple_file_storage::length_i () const
98 Simple_file_storage::~Simple_file_storage ()