1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/stlport/src/fstream.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* 1.5 + * Copyright (c) 1999 1.6 + * Silicon Graphics Computer Systems, Inc. 1.7 + * 1.8 + * Copyright (c) 1999 1.9 + * Boris Fomitchev 1.10 + * 1.11 + * This material is provided "as is", with absolutely no warranty expressed 1.12 + * or implied. Any use is at your own risk. 1.13 + * 1.14 + * Permission to use or copy this software for any purpose is hereby granted 1.15 + * without fee, provided the above notices are retained on all copies. 1.16 + * Permission to modify the code and to distribute modified code is granted, 1.17 + * provided the above notices are retained, and a notice that the code was 1.18 + * modified is included with the above copyright notice. 1.19 + * 1.20 + */ 1.21 + 1.22 +#include "stlport_prefix.h" 1.23 + 1.24 +#ifdef _STLP_USE_UNIX_IO 1.25 +# include "details/fstream_unistd.cpp" 1.26 +#elif defined(_STLP_USE_STDIO_IO) 1.27 +# include "details/fstream_stdio.cpp" 1.28 +#elif defined(_STLP_USE_WIN32_IO) 1.29 +# include "details/fstream_win32io.cpp" 1.30 +#else 1.31 +# error "Can't recognize IO scheme to use" 1.32 +#endif 1.33 + 1.34 +_STLP_BEGIN_NAMESPACE 1.35 + 1.36 +// fbp : let us map 1 MB maximum, just be sure not to trash VM 1.37 +#define MMAP_CHUNK 0x100000L 1.38 + 1.39 +_Underflow< char, char_traits<char> >::int_type _STLP_CALL 1.40 +_Underflow< char, char_traits<char> >::_M_doit(basic_filebuf<char, char_traits<char> >* __this) 1.41 +{ 1.42 + typedef char_traits<char> traits_type; 1.43 + typedef traits_type::int_type int_type; 1.44 + 1.45 + if (!__this->_M_in_input_mode) { 1.46 + if (!__this->_M_switch_to_input_mode()) 1.47 + return traits_type::eof(); 1.48 + } 1.49 + else if (__this->_M_in_putback_mode) { 1.50 + __this->_M_exit_putback_mode(); 1.51 + if (__this->gptr() != __this->egptr()) { 1.52 + int_type __c = traits_type::to_int_type(*__this->gptr()); 1.53 + return __c; 1.54 + } 1.55 + } 1.56 + 1.57 + // If it's a disk file, and if the internal and external character 1.58 + // sequences are guaranteed to be identical, then try to use memory 1.59 + // mapped I/O. Otherwise, revert to ordinary read. 1.60 + if (__this->_M_base.__regular_file() 1.61 + && __this->_M_always_noconv 1.62 + && __this->_M_base._M_in_binary_mode()) { 1.63 + // If we've mmapped part of the file already, then unmap it. 1.64 + if (__this->_M_mmap_base) 1.65 + __this->_M_base._M_unmap(__this->_M_mmap_base, __this->_M_mmap_len); 1.66 + 1.67 + // Determine the position where we start mapping. It has to be 1.68 + // a multiple of the page size. 1.69 + streamoff __cur = __this->_M_base._M_seek(0, ios_base::cur); 1.70 + streamoff __size = __this->_M_base._M_file_size(); 1.71 + if (__size > 0 && __cur >= 0 && __cur < __size) { 1.72 + streamoff __offset = (__cur / __this->_M_base.__page_size()) * __this->_M_base.__page_size(); 1.73 + streamoff __remainder = __cur - __offset; 1.74 + 1.75 + __this->_M_mmap_len = __size - __offset; 1.76 + 1.77 + if (__this->_M_mmap_len > MMAP_CHUNK) 1.78 + __this->_M_mmap_len = MMAP_CHUNK; 1.79 + 1.80 + if ((__this->_M_mmap_base = __this->_M_base._M_mmap(__offset, __this->_M_mmap_len)) != 0) { 1.81 + __this->setg(__STATIC_CAST(char*, __this->_M_mmap_base), 1.82 + __STATIC_CAST(char*, __this->_M_mmap_base) + __STATIC_CAST(ptrdiff_t, __remainder), 1.83 + __STATIC_CAST(char*, __this->_M_mmap_base) + __STATIC_CAST(ptrdiff_t, __this->_M_mmap_len)); 1.84 + return traits_type::to_int_type(*__this->gptr()); 1.85 + } 1.86 + else 1.87 + __this->_M_mmap_len = 0; 1.88 + } 1.89 + else { 1.90 + __this->_M_mmap_base = 0; 1.91 + __this->_M_mmap_len = 0; 1.92 + } 1.93 + } 1.94 + 1.95 + return __this->_M_underflow_aux(); 1.96 +} 1.97 + 1.98 +//---------------------------------------------------------------------- 1.99 +// Force instantiation of filebuf and fstream classes. 1.100 +#if !defined(_STLP_NO_FORCE_INSTANTIATE) 1.101 + 1.102 +template class basic_filebuf<char, char_traits<char> >; 1.103 +template class basic_ifstream<char, char_traits<char> >; 1.104 +template class basic_ofstream<char, char_traits<char> >; 1.105 +template class basic_fstream<char, char_traits<char> >; 1.106 + 1.107 +# if !defined (_STLP_NO_WCHAR_T) 1.108 +template class _Underflow<wchar_t, char_traits<wchar_t> >; 1.109 +template class basic_filebuf<wchar_t, char_traits<wchar_t> >; 1.110 +template class basic_ifstream<wchar_t, char_traits<wchar_t> >; 1.111 +template class basic_ofstream<wchar_t, char_traits<wchar_t> >; 1.112 +template class basic_fstream<wchar_t, char_traits<wchar_t> >; 1.113 +# endif /* _STLP_NO_WCHAR_T */ 1.114 + 1.115 +#endif 1.116 + 1.117 +_STLP_END_NAMESPACE