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.

170 lines
5.0 KiB

  1. /***
  2. *fstream.h - definitions/declarations for filebuf and fstream classes
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines the classes, values, macros, and functions
  8. * used by the filebuf and fstream classes.
  9. * [AT&T C++]
  10. *
  11. * [Public]
  12. *
  13. ****/
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifdef __cplusplus
  18. #ifndef _INC_FSTREAM
  19. #define _INC_FSTREAM
  20. #if !defined(_WIN32)
  21. #error ERROR: Only Win32 target supported!
  22. #endif
  23. #ifdef _MSC_VER
  24. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  25. // alignment.
  26. #pragma pack(push,8)
  27. #include <useoldio.h>
  28. #endif // _MSC_VER
  29. /* Define _CRTIMP */
  30. #ifndef _CRTIMP
  31. #ifdef _DLL
  32. #define _CRTIMP __declspec(dllimport)
  33. #else /* ndef _DLL */
  34. #define _CRTIMP
  35. #endif /* _DLL */
  36. #endif /* _CRTIMP */
  37. #include <iostream.h>
  38. #ifdef _MSC_VER
  39. // C4514: "unreferenced inline function has been removed"
  40. #pragma warning(disable:4514) // disable C4514 warning
  41. // #pragma warning(default:4514) // use this to reenable, if desired
  42. #endif // _MSC_VER
  43. typedef int filedesc;
  44. class _CRTIMP filebuf : public streambuf {
  45. public:
  46. static const int openprot; // default share/prot mode for open
  47. // optional share values for 3rd argument (prot) of open or constructor
  48. static const int sh_none; // exclusive mode no sharing
  49. static const int sh_read; // allow read sharing
  50. static const int sh_write; // allow write sharing
  51. // use (sh_read | sh_write) to allow both read and write sharing
  52. // options for setmode member function
  53. static const int binary;
  54. static const int text;
  55. filebuf();
  56. filebuf(filedesc);
  57. filebuf(filedesc, char *, int);
  58. ~filebuf();
  59. filebuf* attach(filedesc);
  60. filedesc fd() const { return (x_fd==-1) ? EOF : x_fd; }
  61. int is_open() const { return (x_fd!=-1); }
  62. filebuf* open(const char *, int, int = filebuf::openprot);
  63. filebuf* close();
  64. int setmode(int = filebuf::text);
  65. virtual int overflow(int=EOF);
  66. virtual int underflow();
  67. virtual streambuf* setbuf(char *, int);
  68. virtual streampos seekoff(streamoff, ios::seek_dir, int);
  69. // virtual streampos seekpos(streampos, int);
  70. virtual int sync();
  71. private:
  72. filedesc x_fd;
  73. int x_fOpened;
  74. };
  75. class _CRTIMP ifstream : public istream {
  76. public:
  77. ifstream();
  78. ifstream(const char *, int =ios::in, int = filebuf::openprot);
  79. ifstream(filedesc);
  80. ifstream(filedesc, char *, int);
  81. ~ifstream();
  82. streambuf * setbuf(char *, int);
  83. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  84. void attach(filedesc);
  85. filedesc fd() const { return rdbuf()->fd(); }
  86. int is_open() const { return rdbuf()->is_open(); }
  87. void open(const char *, int =ios::in, int = filebuf::openprot);
  88. void close();
  89. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  90. };
  91. class _CRTIMP ofstream : public ostream {
  92. public:
  93. ofstream();
  94. ofstream(const char *, int =ios::out, int = filebuf::openprot);
  95. ofstream(filedesc);
  96. ofstream(filedesc, char *, int);
  97. ~ofstream();
  98. streambuf * setbuf(char *, int);
  99. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  100. void attach(filedesc);
  101. filedesc fd() const { return rdbuf()->fd(); }
  102. int is_open() const { return rdbuf()->is_open(); }
  103. void open(const char *, int =ios::out, int = filebuf::openprot);
  104. void close();
  105. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  106. };
  107. class _CRTIMP fstream : public iostream {
  108. public:
  109. fstream();
  110. fstream(const char *, int, int = filebuf::openprot);
  111. fstream(filedesc);
  112. fstream(filedesc, char *, int);
  113. ~fstream();
  114. streambuf * setbuf(char *, int);
  115. filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
  116. void attach(filedesc);
  117. filedesc fd() const { return rdbuf()->fd(); }
  118. int is_open() const { return rdbuf()->is_open(); }
  119. void open(const char *, int, int = filebuf::openprot);
  120. void close();
  121. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  122. };
  123. // manipulators to dynamically change file access mode (filebufs only)
  124. inline ios& binary(ios& _fstrm) \
  125. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
  126. inline ios& text(ios& _fstrm) \
  127. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
  128. #ifdef _MSC_VER
  129. #pragma pack(pop)
  130. #endif // _MSC_VER
  131. #endif // _INC_FSTREAM
  132. #endif /* __cplusplus */