Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

680 lines
19 KiB

  1. // fstream standard header
  2. #pragma once
  3. #ifndef _FSTREAM_
  4. #define _FSTREAM_
  5. #include <istream>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. #pragma warning(disable: 4127)
  9. _STD_BEGIN
  10. extern _CRTIMP2 _Filet *__cdecl _Fiopen(const char *, ios_base::openmode);
  11. // TEMPLATE FUNCTION _Fgetc
  12. template<class _Elem> inline
  13. bool _Fgetc(_Elem& _Ch, _Filet *_File)
  14. { // get an element from a C stream
  15. return (fread(&_Ch, sizeof (_Elem), 1, _File) == 1);
  16. }
  17. template<> inline bool _Fgetc(char& _Byte, _Filet *_File)
  18. { // get a char element from a C stream
  19. int _Meta;
  20. if ((_Meta = fgetc(_File)) == EOF)
  21. return (false);
  22. else
  23. { // got one, convert to char
  24. _Byte = (char)_Meta;
  25. return (true);
  26. }
  27. }
  28. template<> inline bool _Fgetc(wchar_t& _Wchar, _Filet *_File)
  29. { // get a wchar_t element from a C stream
  30. wint_t _Meta;
  31. if ((_Meta = fgetwc(_File)) == WEOF)
  32. return (false);
  33. else
  34. { // got one, convert to wchar_t
  35. _Wchar = (wchar_t)_Meta;
  36. return (true);
  37. }
  38. }
  39. // TEMPLATE FUNCTION _Fputc
  40. template<class _Elem> inline
  41. bool _Fputc(_Elem _Ch, _Filet *_File)
  42. { // put an element to a C stream
  43. return (fwrite(&_Ch, sizeof (_Elem), 1, _File) == 1);
  44. }
  45. template<> inline bool _Fputc(char _Byte, _Filet *_File)
  46. { // put a char element to a C stream
  47. return (fputc(_Byte, _File) != EOF);
  48. }
  49. template<> inline bool _Fputc(wchar_t _Wchar, _Filet *_File)
  50. { // put a wchar_t element to a C stream
  51. return (fputwc(_Wchar, _File) != WEOF);
  52. }
  53. // TEMPLATE FUNCTION _Ungetc
  54. template<class _Elem> inline
  55. bool _Ungetc(const _Elem& _Ch, _Filet *_File)
  56. { // put back an arbitrary element to a C stream (always fail)
  57. return (false);
  58. }
  59. template<> inline bool _Ungetc(const char& _Byte, _Filet *_File)
  60. { // put back a char element to a C stream
  61. return (ungetc((unsigned char)_Byte, _File) != EOF);
  62. }
  63. template<> inline bool _Ungetc(const signed char& _Byte, _Filet *_File)
  64. { // put back a signed char element to a C stream
  65. return (ungetc((unsigned char)_Byte, _File) != EOF);
  66. }
  67. template<> inline bool _Ungetc(const unsigned char& _Byte, _Filet *_File)
  68. { // put back an unsigned char element to a C stream
  69. return (ungetc(_Byte, _File) != EOF);
  70. }
  71. template<> inline bool _Ungetc(const wchar_t& _Wchar, _Filet *_File)
  72. { // put back a wchar_t element to a C stream
  73. return (ungetwc(_Wchar, _File) != WEOF);
  74. }
  75. // TEMPLATE CLASS basic_filebuf
  76. template<class _Elem,
  77. class _Traits>
  78. class basic_filebuf
  79. : public basic_streambuf<_Elem, _Traits>
  80. { // stream buffer associated with a C stream
  81. public:
  82. typedef basic_filebuf<_Elem, _Traits> _Myt;
  83. typedef basic_streambuf<_Elem, _Traits> _Mysb;
  84. typedef codecvt<_Elem, char, typename _Traits::state_type> _Cvt;
  85. virtual ~basic_filebuf()
  86. { // destroy the object
  87. if (_Closef)
  88. close();
  89. _DELETE_CRT(_Mystr);
  90. }
  91. basic_filebuf(_Filet *_File = 0)
  92. : _Mysb(), _Mystr(0)
  93. { // construct from pointer to C stream
  94. _Init(_File, _Newfl);
  95. }
  96. typedef typename _Traits::int_type int_type;
  97. typedef typename _Traits::pos_type pos_type;
  98. typedef typename _Traits::off_type off_type;
  99. basic_filebuf(_Uninitialized)
  100. : _Mysb(_Noinit)
  101. { // construct uninitialized
  102. }
  103. enum _Initfl
  104. { // reasons for a call to _Init
  105. _Newfl, _Openfl, _Closefl};
  106. bool is_open() const
  107. { // test if C stream has been opened
  108. return (_Myfile != 0);
  109. }
  110. _Myt *open(const char *_Filename, ios_base::openmode _Mode)
  111. { // open a C stream with specified mode
  112. _Filet *_File;
  113. if (_Myfile != 0 || (_File = _Fiopen(_Filename, _Mode)) == 0)
  114. return (0); // open failed
  115. _Init(_File, _Openfl);
  116. _Initcvt((_Cvt *)&_USE(_Mysb::getloc(), _Cvt));
  117. return (this); // open succeeded
  118. }
  119. _Myt *open(const char *_Filename, ios_base::open_mode _Mode)
  120. { // open a C stream with specified mode (old style)
  121. return (open(_Filename, (ios_base::openmode)_Mode));
  122. }
  123. _Myt *close()
  124. { // close the C stream
  125. if (_Myfile != 0 && _Endwrite() && fclose(_Myfile) == 0)
  126. { // close succeeded, tidy up
  127. _Init(0, _Closefl);
  128. return (this);
  129. }
  130. else
  131. return (0);
  132. }
  133. protected:
  134. virtual int_type overflow(int_type _Meta = _Traits::eof())
  135. { // put an element to stream
  136. if (_Traits::eq_int_type(_Traits::eof(), _Meta))
  137. return (_Traits::not_eof(_Meta)); // EOF, return success code
  138. else if (_Mysb::pptr() != 0
  139. && _Mysb::pptr() < _Mysb::epptr())
  140. { // room in buffer, store it
  141. *_Mysb::_Pninc() = _Traits::to_char_type(_Meta);
  142. return (_Meta);
  143. }
  144. else if (_Myfile == 0)
  145. return (_Traits::eof()); // no open C stream, fail
  146. else if (_Pcvt == 0)
  147. return (_Fputc(_Traits::to_char_type(_Meta), _Myfile)
  148. ? _Meta : _Traits::eof()); // no codecvt facet, put as is
  149. else
  150. { // put using codecvt facet
  151. const int _STRING_INC = 8;
  152. const _Elem _Ch = _Traits::to_char_type(_Meta);
  153. const _Elem *_Source;
  154. char *_Dest;
  155. _Mystr->erase();
  156. string _Str(_STRING_INC, '\0');
  157. for (; ; )
  158. switch (_Pcvt->out(_State,
  159. &_Ch, &_Ch + 1, _Source,
  160. &*_Str.begin(), &*_Str.end(), _Dest))
  161. { // test result of converting one element
  162. case codecvt_base::partial:
  163. case codecvt_base::ok:
  164. { // converted something, try to put it out
  165. size_t _Count = _Dest - &*_Str.begin();
  166. if (0 < _Count && _Count !=
  167. fwrite(&*_Str.begin(), 1, _Count, _Myfile))
  168. return (_Traits::eof()); // write failed
  169. _Wrotesome = true; // write succeeded
  170. if (_Source != &_Ch)
  171. return (_Meta); // converted whole element
  172. if (_Count == 0)
  173. _Str.append(_STRING_INC, '\0'); // try some more
  174. break;
  175. }
  176. case codecvt_base::noconv:
  177. return (_Fputc(_Ch, _Myfile) ? _Meta
  178. : _Traits::eof()); // no conversion, put as is
  179. default:
  180. return (_Traits::eof()); // conversion failed
  181. }
  182. }
  183. }
  184. virtual int_type pbackfail(int_type _Meta = _Traits::eof())
  185. { // put an element back to stream
  186. if (_Mysb::gptr() != 0
  187. && _Mysb::eback() < _Mysb::gptr()
  188. && (_Traits::eq_int_type(_Traits::eof(), _Meta)
  189. || _Traits::eq_int_type(_Traits::to_int_type(_Mysb::gptr()[-1]),
  190. _Meta)))
  191. { // just back up position
  192. _Mysb::_Gndec();
  193. return (_Traits::not_eof(_Meta));
  194. }
  195. else if (_Myfile == 0 || _Traits::eq_int_type(_Traits::eof(), _Meta))
  196. return (_Traits::eof()); // no open C stream or EOF, fail
  197. else if (_Pcvt == 0 && _Ungetc(_Traits::to_char_type(_Meta), _Myfile))
  198. return (_Meta); // no facet and unget succeeded, return
  199. else
  200. { // putback to _Mychar
  201. _Mychar = _Traits::to_char_type(_Meta);
  202. _Mysb::setg(&_Mychar, &_Mychar, &_Mychar + 1);
  203. return (_Meta);
  204. }
  205. }
  206. virtual int_type underflow()
  207. { // get an element from stream, but don't point past it
  208. int_type _Meta;
  209. if (_Mysb::gptr() != 0
  210. && _Mysb::gptr() < _Mysb::egptr())
  211. return (_Traits::to_int_type(*_Mysb::gptr())); // return buffered
  212. else if (_Traits::eq_int_type(_Traits::eof(), _Meta = uflow()))
  213. return (_Meta); // uflow failed, return EOF
  214. else
  215. { // get a char, don't point past it
  216. pbackfail(_Meta);
  217. return (_Meta);
  218. }
  219. }
  220. virtual int_type uflow()
  221. { // get an element from stream, point past it
  222. if (_Mysb::gptr() != 0
  223. && _Mysb::gptr() < _Mysb::egptr())
  224. return (_Traits::to_int_type(
  225. *_Mysb::_Gninc())); // return buffered
  226. else if (_Myfile == 0)
  227. return (_Traits::eof()); // no open C stream, fail
  228. else if (_Pcvt == 0)
  229. { // no codecvt facet, just get it
  230. _Elem _Ch = 0;
  231. return (_Fgetc(_Ch, _Myfile) ? _Traits::to_int_type(_Ch)
  232. : _Traits::eof());
  233. }
  234. else
  235. for (_State0 = _State, _Mystr->erase(); ; )
  236. { // get using codecvt facet
  237. _Elem _Ch, *_Dest;
  238. const char *_Source;
  239. int _Meta = fgetc(_Myfile);
  240. if (_Meta == EOF)
  241. return (_Traits::eof()); // partial char?
  242. _Mystr->append(1, (char)_Meta); // append byte and convert
  243. _State = _State0;
  244. switch (_Pcvt->in(_State,
  245. &*_Mystr->begin(), &*_Mystr->end(), _Source,
  246. &_Ch, &_Ch + 1, _Dest))
  247. { // test result of converting one element
  248. case codecvt_base::partial:
  249. break; // partial, not done yet
  250. case codecvt_base::noconv:
  251. if (_Mystr->size() < sizeof (_Elem))
  252. break; // no conversion, but need more chars
  253. memcpy(&_Ch, &*_Mystr->begin(),
  254. sizeof (_Elem)); // copy raw bytes to element
  255. case codecvt_base::ok: // can fall through
  256. return (_Traits::to_int_type(_Ch)); // return result
  257. default:
  258. return (_Traits::eof()); // conversion failed
  259. }
  260. }
  261. }
  262. virtual pos_type seekoff(off_type _Off, ios_base::seekdir _Way,
  263. ios_base::openmode =
  264. (ios_base::openmode)(ios_base::in | ios_base::out))
  265. { // change position by _Off
  266. fpos_t _Fileposition;
  267. if (_Mysb::gptr() != &_Mychar
  268. || _Mysb::egptr() <= _Mysb::gptr()
  269. || _Way != ios_base::cur)
  270. ; // don't have to worry about putback character
  271. else if (_Pcvt == 0)
  272. _Off -= (off_type)sizeof (_Elem); // back up over _Elem bytes
  273. else
  274. { // back up over converted bytes
  275. _Off -= (off_type)_Mystr->size();
  276. _Mystr->erase();
  277. _State = _State0;
  278. }
  279. if (_Myfile == 0 || !_Endwrite()
  280. || (_Off != 0 || _Way != ios_base::cur)
  281. && fseek(_Myfile, (long)_Off, _Way) != 0
  282. || fgetpos(_Myfile, &_Fileposition) != 0)
  283. return (pos_type(_BADOFF)); // report failure
  284. if (_Mysb::gptr() == &_Mychar)
  285. _Mysb::setg(&_Mychar, &_Mychar, &_Mychar); // discard putback
  286. return (pos_type(_State, _Fileposition)); // return new position
  287. }
  288. virtual pos_type seekpos(pos_type _Pos,
  289. ios_base::openmode =
  290. (ios_base::openmode)(ios_base::in | ios_base::out))
  291. { // change position to _Pos
  292. fpos_t _Fileposition = _Pos.seekpos();
  293. off_type _Off = (off_type)_Pos - _FPOSOFF(_Fileposition);
  294. if (_Myfile == 0 || !_Endwrite()
  295. || fsetpos(_Myfile, &_Fileposition) != 0
  296. || _Off != 0 && fseek(_Myfile, (long)_Off, SEEK_CUR) != 0
  297. || fgetpos(_Myfile, &_Fileposition) != 0)
  298. return (pos_type(_BADOFF)); // report failure
  299. if (_Mystr != 0)
  300. _State = _Pos.state(), _Mystr->erase(); // restore state
  301. if (_Mysb::gptr() == &_Mychar)
  302. _Mysb::setg(&_Mychar, &_Mychar, &_Mychar); // discard putback
  303. return (pos_type(_State, _Fileposition)); // return new position
  304. }
  305. virtual _Mysb *setbuf(_Elem *_Buffer, streamsize _Count)
  306. { // offer _Buffer to C stream
  307. return (_Myfile == 0 || setvbuf(_Myfile, (char *)_Buffer,
  308. _Buffer == 0 && _Count == 0 ? _IONBF : _IOFBF,
  309. _Count * sizeof (_Elem)) != 0 ? 0 : this);
  310. }
  311. virtual int sync()
  312. { // synchronize C stream with external file
  313. return (_Myfile == 0
  314. || _Traits::eq_int_type(_Traits::eof(), overflow())
  315. || 0 <= fflush(_Myfile) ? 0 : -1);
  316. }
  317. virtual void imbue(const locale& _Loc)
  318. { // set locale to argument (capture nontrivial codecvt facet)
  319. _Initcvt((_Cvt *)&_USE(_Loc, _Cvt));
  320. }
  321. void _Init(_Filet *_File, _Initfl _Which)
  322. { // initialize to C stream _File after {new, open, close}
  323. static typename _Traits::state_type _Stinit; // initial state
  324. _Closef = _Which == _Openfl;
  325. _Wrotesome = false;
  326. _Mysb::_Init(); // initialize stream buffer base object
  327. #ifndef _IORCNT
  328. #define _IORCNT _IOCNT /* read and write counts are the same */
  329. #define _IOWCNT _IOCNT
  330. #endif
  331. if (_File != 0 && sizeof (_Elem) == 1)
  332. { // point inside C stream with [first, first + count) buffer
  333. _Elem **_Pb = (_Elem **)&_File->_IOBASE;
  334. _Elem **_Pn = (_Elem **)&_File->_IOPTR;
  335. int *_Nr = (int *)&_File->_IORCNT;
  336. int *_Nw = (int *)&_File->_IOWCNT;
  337. _Mysb::_Init(_Pb, _Pn, _Nr, _Pb, _Pn, _Nw);
  338. }
  339. _Myfile = _File;
  340. _State = _Stinit;
  341. _State0 = _Stinit;
  342. _Pcvt = 0; // pointer to codecvt facet
  343. }
  344. bool _Endwrite()
  345. { // put shift to initial conversion state, as needed
  346. if (_Pcvt == 0 || !_Wrotesome)
  347. return (true);
  348. else
  349. { // may have to put
  350. const int _STRING_INC = 8;
  351. char *_Dest;
  352. overflow();
  353. string _Str(_STRING_INC, '\0');
  354. for (; ; )
  355. switch (_Pcvt->unshift(_State,
  356. &*_Str.begin(), &*_Str.end(), _Dest))
  357. { // test result of homing conversion
  358. case codecvt_base::ok:
  359. _Wrotesome = false; // homed successfully
  360. case codecvt_base::partial: // can fall through
  361. { // put any generated bytes
  362. size_t _Count = _Dest - &*_Str.begin();
  363. if (0 < _Count && _Count !=
  364. fwrite(&*_Str.begin(), _Count, 1, _Myfile))
  365. return (false); // write failed
  366. if (!_Wrotesome)
  367. return (true);
  368. _Str.append(_STRING_INC, '\0'); // try some more
  369. break;
  370. }
  371. case codecvt_base::noconv:
  372. return (true); // nothing to do
  373. default:
  374. return (false); // conversion failed
  375. }
  376. }
  377. }
  378. void _Initcvt(_Cvt *_Newpcvt)
  379. { // initialize codecvt pointer
  380. if (_Newpcvt->always_noconv())
  381. _Pcvt = 0; // nothing to do
  382. else
  383. { // set up for nontrivial codecvt facet
  384. _Pcvt = _Newpcvt;
  385. _Mysb::_Init(); // reset any buffering
  386. if (_Mystr == 0)
  387. _Mystr = _NEW_CRT _STRING_CRT; // buy conversion buffer
  388. }
  389. }
  390. private:
  391. _Cvt *_Pcvt; // pointer to codecvt facet (may be null)
  392. typename _Traits::state_type _State0; // rollback for bad conversion
  393. _Elem _Mychar; // putback character, when _Ungetc fails
  394. _STRING_CRT *_Mystr; // string to hold partial conversion byte sequences
  395. bool _Wrotesome; // true if homing sequence may be needed
  396. typename _Traits::state_type _State; // current conversion state
  397. bool _Closef; // true if C stream must be closed
  398. int _Dummy[sizeof(locale)/sizeof(int)]; // retain old _Loc member space
  399. _Filet *_Myfile; // pointer to C stream
  400. };
  401. #ifdef _DLL_CPPLIB
  402. template class _CRTIMP2 basic_filebuf<char,
  403. char_traits<char> >;
  404. template class _CRTIMP2 basic_filebuf<wchar_t,
  405. char_traits<wchar_t> >;
  406. #endif // _DLL_CPPLIB
  407. // TEMPLATE CLASS basic_ifstream
  408. template<class _Elem,
  409. class _Traits>
  410. class basic_ifstream
  411. : public basic_istream<_Elem, _Traits>
  412. { // input stream associated with a C stream
  413. public:
  414. typedef basic_ifstream<_Elem, _Traits> _Myt;
  415. typedef basic_filebuf<_Elem, _Traits> _Myfb;
  416. typedef basic_ios<_Elem, _Traits> _Myios;
  417. basic_ifstream()
  418. : basic_istream<_Elem, _Traits>(&_Filebuffer)
  419. { // construct unopened
  420. }
  421. explicit basic_ifstream(const char *_Filename,
  422. ios_base::openmode _Mode = ios_base::in)
  423. : basic_istream<_Elem, _Traits>(&_Filebuffer)
  424. { // construct with named file and specified mode
  425. if (_Filebuffer.open(_Filename, _Mode | ios_base::in) == 0)
  426. _Myios::setstate(ios_base::failbit);
  427. }
  428. virtual ~basic_ifstream()
  429. { // destroy the object
  430. }
  431. _Myfb *rdbuf() const
  432. { // return pointer to file buffer
  433. return ((_Myfb *)&_Filebuffer);
  434. }
  435. bool is_open() const
  436. { // test if C stream has been opened
  437. return (_Filebuffer.is_open());
  438. }
  439. void open(const char *_Filename,
  440. ios_base::openmode _Mode = ios_base::in)
  441. { // open a C stream with specified mode
  442. if (_Filebuffer.open(_Filename, _Mode | ios_base::in) == 0)
  443. _Myios::setstate(ios_base::failbit);
  444. }
  445. void open(const char *_Filename, ios_base::open_mode _Mode)
  446. { // open named file with specified mode (old style)
  447. open(_Filename, (ios_base::openmode)_Mode);
  448. }
  449. void close()
  450. { // close the C stream
  451. if (_Filebuffer.close() == 0)
  452. _Myios::setstate(ios_base::failbit);
  453. }
  454. private:
  455. _Myfb _Filebuffer; // the file buffer
  456. };
  457. #ifdef _DLL_CPPLIB
  458. template class _CRTIMP2 basic_ifstream<char,
  459. char_traits<char> >;
  460. template class _CRTIMP2 basic_ifstream<wchar_t,
  461. char_traits<wchar_t> >;
  462. #endif // _DLL_CPPLIB
  463. // TEMPLATE CLASS basic_ofstream
  464. template<class _Elem,
  465. class _Traits>
  466. class basic_ofstream
  467. : public basic_ostream<_Elem, _Traits>
  468. { // output stream associated with a C stream
  469. public:
  470. typedef basic_ofstream<_Elem, _Traits> _Myt;
  471. typedef basic_filebuf<_Elem, _Traits> _Myfb;
  472. typedef basic_ios<_Elem, _Traits> _Myios;
  473. basic_ofstream()
  474. : basic_ostream<_Elem, _Traits>(&_Filebuffer)
  475. { // construct unopened
  476. }
  477. explicit basic_ofstream(const char *_Filename,
  478. ios_base::openmode _Mode = ios_base::out)
  479. : basic_ostream<_Elem, _Traits>(&_Filebuffer)
  480. { // construct with named file and specified mode
  481. if (_Filebuffer.open(_Filename, _Mode | ios_base::out) == 0)
  482. _Myios::setstate(ios_base::failbit);
  483. }
  484. virtual ~basic_ofstream()
  485. { // destroy the object
  486. }
  487. _Myfb *rdbuf() const
  488. { // return pointer to file buffer
  489. return ((_Myfb *)&_Filebuffer);
  490. }
  491. bool is_open() const
  492. { // test if C stream has been opened
  493. return (_Filebuffer.is_open());
  494. }
  495. void open(const char *_Filename,
  496. ios_base::openmode _Mode = ios_base::out)
  497. { // open a C stream with specified mode
  498. if (_Filebuffer.open(_Filename, _Mode | ios_base::out) == 0)
  499. _Myios::setstate(ios_base::failbit);
  500. }
  501. void open(const char *_Filename, ios_base::open_mode _Mode)
  502. { // open a C stream with specified mode (old style)
  503. open(_Filename, (ios_base::openmode)_Mode);
  504. }
  505. void close()
  506. { // close the C stream
  507. if (_Filebuffer.close() == 0)
  508. _Myios::setstate(ios_base::failbit);
  509. }
  510. private:
  511. _Myfb _Filebuffer; // the file buffer
  512. };
  513. #ifdef _DLL_CPPLIB
  514. template class _CRTIMP2 basic_ofstream<char,
  515. char_traits<char> >;
  516. template class _CRTIMP2 basic_ofstream<wchar_t,
  517. char_traits<wchar_t> >;
  518. #endif // _DLL_CPPLIB
  519. // TEMPLATE CLASS basic_fstream
  520. template<class _Elem,
  521. class _Traits>
  522. class basic_fstream
  523. : public basic_iostream<_Elem, _Traits>
  524. { // input/output stream associated with a C stream
  525. public:
  526. typedef basic_ios<_Elem, _Traits> _Myios;
  527. typedef _Elem char_type;
  528. typedef _Traits traits_type;
  529. typedef typename _Traits::int_type int_type;
  530. typedef typename _Traits::pos_type pos_type;
  531. typedef typename _Traits::off_type off_type;
  532. basic_fstream()
  533. : basic_iostream<_Elem, _Traits>(&_Filebuffer)
  534. { // construct unopened
  535. }
  536. explicit basic_fstream(const char *_Filename,
  537. ios_base::openmode _Mode = ios_base::in | ios_base::out)
  538. : basic_iostream<_Elem, _Traits>(&_Filebuffer)
  539. { // construct with named file and specified mode
  540. if (_Filebuffer.open(_Filename, _Mode) == 0)
  541. _Myios::setstate(ios_base::failbit);
  542. }
  543. virtual ~basic_fstream()
  544. { // destroy the object
  545. }
  546. basic_filebuf<_Elem, _Traits> *rdbuf() const
  547. { // return pointer to file buffer
  548. return ((basic_filebuf<_Elem, _Traits> *)&_Filebuffer);
  549. }
  550. bool is_open() const
  551. { // test if C stream has been opened
  552. return (_Filebuffer.is_open());
  553. }
  554. void open(const char *_Filename,
  555. ios_base::openmode _Mode = ios_base::in | ios_base::out)
  556. { // open a C stream with specified mode
  557. if (_Filebuffer.open(_Filename, _Mode) == 0)
  558. _Myios::setstate(ios_base::failbit);
  559. }
  560. void open(const char *_Filename, ios_base::open_mode _Mode)
  561. { // open a C stream with specified mode (old style)
  562. open(_Filename, (ios_base::openmode)_Mode);
  563. }
  564. void close()
  565. { // close the C stream
  566. if (_Filebuffer.close() == 0)
  567. _Myios::setstate(ios_base::failbit);
  568. }
  569. private:
  570. basic_filebuf<_Elem, _Traits> _Filebuffer; // the file buffer
  571. };
  572. #ifdef _DLL_CPPLIB
  573. template class _CRTIMP2 basic_fstream<char,
  574. char_traits<char> >;
  575. template class _CRTIMP2 basic_fstream<wchar_t,
  576. char_traits<wchar_t> >;
  577. #endif // _DLL_CPPLIB
  578. _STD_END
  579. #pragma warning(default: 4127)
  580. #pragma warning(pop)
  581. #pragma pack(pop)
  582. #endif /* _FSTREAM_ */
  583. /*
  584. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  585. * Consult your license regarding permissions and restrictions.
  586. V3.10:0009 */