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>
15 #include "simple-file-storage.hh"
21 Simple_file_storage::load_stdin ()
28 while ((c = fgetc (stdin)) != EOF)
30 len_i_ = ch_arr.size ();
31 data_p_ = ch_arr.remove_array_p ();
35 Simple_file_storage::load_file (String s)
38 let's hope that "b" opens anything binary, and does not apply
41 FILE * f = fopen (s.ch_C (), "rb");
45 warning (_ ("can't open file `") + s + "'");
49 int ret = fseek (f, 0, SEEK_END);
52 data_p_ = new char[len_i_+1];
54 ret = fread (data_p_, sizeof (char), len_i_, f);
57 warning (_ ("Huh? got ") + String (ret) + _ (", expected ")
58 + String (len_i_) + _ (" characters"));
64 Stupid but foolproof way of opening files.
67 Should check IO status
69 This is of course a build it yourself version of mmap, so we should
70 have been using that... (see Mapped_file_storage) But we noticed
71 some problems with this (unexplained lexer crashes)
73 [Some versions later] The crashes aren't caused by the mmap
74 code. But no reason to take it out, is there? mmap ()
78 Simple_file_storage::Simple_file_storage (String s)
90 Simple_file_storage::ch_C () const
96 Simple_file_storage::length_i () const
102 Simple_file_storage::~Simple_file_storage ()