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 "file-storage.hh"
17 Stupid but foolproof way of opening files.
20 Should check IO status
22 This is of course a build it yourself version of mmap, so we should
23 have been using that... (see Mapped_file_storage) But we noticed
24 some problems with this (unexplained lexer crashes)
26 [Some versions later] The crashes aren't caused by the mmap
27 code. But no reason to take it out, is there? */
29 Simple_file_storage::Simple_file_storage(String s)
34 let's hope that "b" opens anything binary, and does not apply
37 FILE * f = (s) ? fopen (s.ch_C(), "rb") : stdin;
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);
54 warning ("Huh? got " + String(ret) + ", expected "
55 + String(len_i_) + " characters");
62 Simple_file_storage::ch_C() const
68 Simple_file_storage::length_i() const
74 Simple_file_storage::~Simple_file_storage()