From: fred Date: Tue, 12 Aug 1997 23:01:22 +0000 (+0000) Subject: lilypond-0.1.7 X-Git-Tag: release/1.5.59~6069 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5833a72b64de20397d3dc9ce4a82f852578c0daf;p=lilypond.git lilypond-0.1.7 --- diff --git a/lib/simple-file-storage.cc b/lib/simple-file-storage.cc new file mode 100644 index 0000000000..be022cee02 --- /dev/null +++ b/lib/simple-file-storage.cc @@ -0,0 +1,63 @@ +/* + simple-file-storage.cc -- implement Simple_file_storage + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + +#include + +#include "file-storage.hh" +#include "varray.hh" +#include "string.hh" +#include "warn.hh" + +/** + Stupid but foolproof way of opening files. + + TODO + Should use obstack. Should check IO status + + This is of course a build it yourself version of mmap, so we should + have been using that... (see Mapped_file_storage) But we noticed + some problems with this (unexplained lexer crashes) + + */ + +Simple_file_storage::Simple_file_storage(String s) +{ + data_p_ =0; + FILE * f = fopen ( s.ch_C(), "r"); + if ( !f ) { + warning("can't open file\n"); + return ; + } + + int ret = fseek( f, 0, SEEK_END); + len_i_ = ftell(f); + rewind(f); + data_p_ = new char[len_i_+1]; + data_p_[len_i_] = 0; + ret = fread(data_p_, sizeof(char), len_i_, f); + assert (ret==len_i_); + fclose(f); +} + +char const* +Simple_file_storage::ch_C() const +{ + return data_p_; +} + +int +Simple_file_storage::length_i()const +{ + return len_i_; +} + + +Simple_file_storage::~Simple_file_storage() +{ + delete []data_p_; +}