ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

fstream.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 #include "stlport_prefix.h"
00020 
00021 #ifdef _STLP_USE_UNIX_IO
00022 # include "details/fstream_unistd.cpp"
00023 #elif defined(_STLP_USE_STDIO_IO)
00024 # include "details/fstream_stdio.cpp"
00025 #elif defined(_STLP_USE_WIN32_IO)
00026 # include "details/fstream_win32io.cpp"
00027 #else
00028 #  error "Can't recognize IO scheme to use"
00029 #endif
00030 
00031 _STLP_BEGIN_NAMESPACE
00032 
00033 // fbp : let us map 1 MB maximum, just be sure not to trash VM
00034 #define MMAP_CHUNK 0x100000L
00035 
00036 _Underflow< char, char_traits<char> >::int_type _STLP_CALL
00037 _Underflow< char, char_traits<char> >::_M_doit(basic_filebuf<char, char_traits<char> >* __this)
00038 {
00039   typedef char_traits<char> traits_type;
00040   typedef traits_type::int_type int_type;
00041 
00042   if (!__this->_M_in_input_mode) {
00043     if (!__this->_M_switch_to_input_mode())
00044       return traits_type::eof();
00045   }
00046   else if (__this->_M_in_putback_mode) {
00047     __this->_M_exit_putback_mode();
00048     if (__this->gptr() != __this->egptr()) {
00049       int_type __c = traits_type::to_int_type(*__this->gptr());
00050       return __c;
00051     }
00052   }
00053 
00054   // If it's a disk file, and if the internal and external character
00055   // sequences are guaranteed to be identical, then try to use memory
00056   // mapped I/O.  Otherwise, revert to ordinary read.
00057   if (__this->_M_base.__regular_file()
00058       && __this->_M_always_noconv
00059       && __this->_M_base._M_in_binary_mode()) {
00060     // If we've mmapped part of the file already, then unmap it.
00061     if (__this->_M_mmap_base)
00062       __this->_M_base._M_unmap(__this->_M_mmap_base, __this->_M_mmap_len);
00063 
00064     // Determine the position where we start mapping.  It has to be
00065     // a multiple of the page size.
00066     streamoff __cur = __this->_M_base._M_seek(0, ios_base::cur);
00067     streamoff __size = __this->_M_base._M_file_size();
00068     if (__size > 0 && __cur >= 0 && __cur < __size) {
00069       streamoff __offset = (__cur / __this->_M_base.__page_size()) * __this->_M_base.__page_size();
00070       streamoff __remainder = __cur - __offset;
00071 
00072       __this->_M_mmap_len = __size - __offset;
00073 
00074       if (__this->_M_mmap_len > MMAP_CHUNK)
00075         __this->_M_mmap_len = MMAP_CHUNK;
00076 
00077       if ((__this->_M_mmap_base = __this->_M_base._M_mmap(__offset, __this->_M_mmap_len)) != 0) {
00078         __this->setg(__STATIC_CAST(char*, __this->_M_mmap_base),
00079                      __STATIC_CAST(char*, __this->_M_mmap_base) + __STATIC_CAST(ptrdiff_t, __remainder),
00080                      __STATIC_CAST(char*, __this->_M_mmap_base) + __STATIC_CAST(ptrdiff_t, __this->_M_mmap_len));
00081         return traits_type::to_int_type(*__this->gptr());
00082       }
00083       else
00084         __this->_M_mmap_len = 0;
00085     }
00086     else {
00087       __this->_M_mmap_base = 0;
00088       __this->_M_mmap_len = 0;
00089     }
00090   }
00091 
00092   return __this->_M_underflow_aux();
00093 }
00094 
00095 //----------------------------------------------------------------------
00096 // Force instantiation of filebuf and fstream classes.
00097 #if !defined(_STLP_NO_FORCE_INSTANTIATE)
00098 
00099 template class basic_filebuf<char, char_traits<char> >;
00100 template class basic_ifstream<char, char_traits<char> >;
00101 template class basic_ofstream<char, char_traits<char> >;
00102 template class basic_fstream<char, char_traits<char> >;
00103 
00104 #  if !defined (_STLP_NO_WCHAR_T)
00105 template class _Underflow<wchar_t, char_traits<wchar_t> >;
00106 template class basic_filebuf<wchar_t, char_traits<wchar_t> >;
00107 template class basic_ifstream<wchar_t, char_traits<wchar_t> >;
00108 template class basic_ofstream<wchar_t, char_traits<wchar_t> >;
00109 template class basic_fstream<wchar_t, char_traits<wchar_t> >;
00110 #  endif /* _STLP_NO_WCHAR_T */
00111 
00112 #endif
00113 
00114 _STLP_END_NAMESPACE

Generated on Sun May 27 2012 04:35:11 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.