2 file-storage.cc -- implement Mapped_file_storage
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 Jan Nieuwenhuizen <jan@digicash.com>
9 #include <sys/types.h> // open, mmap
10 #include <sys/stat.h> // open
11 #include <sys/mman.h> // mmap
12 #include <limits.h> // INT_MAX
13 #include <fcntl.h> // open
14 #include <unistd.h> // close, stat
15 #include <stdio.h> // fdopen
16 #include <string.h> // strerror
17 #include <errno.h> // errno
24 #include "file-storage.hh"
26 Mapped_file_storage::Mapped_file_storage(String s
)
35 Mapped_file_storage::ch_C()const
37 return (char const*)data_caddr_
;
41 Mapped_file_storage::map()
43 if ( fildes_i_
== -1 )
46 data_caddr_
= (caddr_t
)mmap( (void*)0, size_off_
, PROT_READ
, MAP_SHARED
, fildes_i_
, 0 );
48 if ( (int)data_caddr_
== -1 )
49 warning( String( "can't map: error no: " ) + strerror( errno
));
54 Mapped_file_storage::open(String name_str
)
56 fildes_i_
= ::open( name_str
, O_RDONLY
);
58 if ( fildes_i_
== -1 )
60 warning( String( "can't open: " ) + name_str
+ String( ": " ) + strerror( errno
));
64 struct stat file_stat
;
65 fstat( fildes_i_
, &file_stat
);
66 size_off_
= file_stat
.st_size
;
71 Mapped_file_storage::unmap()
75 munmap( data_caddr_
, size_off_
);
82 Mapped_file_storage::close()
93 Mapped_file_storage::length_i()const
98 Mapped_file_storage::~Mapped_file_storage()