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.

141 lines
4.2 KiB

  1. /***
  2. *fstream.h - definitions/declarations for filebuf and fstream classes
  3. *
  4. * Copyright (c) 1991-1992, 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. ****/
  12. #ifndef _INC_FSTREAM
  13. #define _INC_FSTREAM
  14. #include <iostream.h>
  15. // Force word packing to avoid possible -Zp override
  16. #pragma pack(2)
  17. #pragma warning(disable:4505) // disable unwanted /W4 warning
  18. // #pragma warning(default:4505) // use this to reenable, if necessary
  19. #ifdef M_I86HM
  20. #define _HFAR_ __far
  21. #else
  22. #define _HFAR_
  23. #endif
  24. typedef int filedesc;
  25. class filebuf : public streambuf {
  26. public:
  27. static const int openprot; // default share/prot mode for open
  28. // optional share values for 3rd argument (prot) of open or constructor
  29. static const int sh_compat; // compatibility share mode
  30. static const int sh_none; // exclusive mode no sharing
  31. static const int sh_read; // allow read sharing
  32. static const int sh_write; // allow write sharing
  33. // use (sh_read | sh_write) to allow both read and write sharing
  34. // options for setmode member function
  35. static const int binary;
  36. static const int text;
  37. filebuf();
  38. filebuf(filedesc);
  39. filebuf(filedesc, char _HFAR_ *, int);
  40. ~filebuf();
  41. filebuf* attach(filedesc);
  42. filedesc fd() const { return (x_fd==-1) ? EOF : x_fd; }
  43. int is_open() const { return (x_fd!=-1); }
  44. filebuf* open(const char _HFAR_ *, int, int = filebuf::openprot);
  45. filebuf* close();
  46. int setmode(int = filebuf::text);
  47. virtual int overflow(int=EOF);
  48. virtual int underflow();
  49. virtual streambuf* setbuf(char _HFAR_ *, int);
  50. virtual streampos seekoff(streamoff, ios::seek_dir, int);
  51. // virtual streampos seekpos(streampos, int);
  52. virtual int sync();
  53. private:
  54. filedesc x_fd;
  55. int x_fOpened;
  56. };
  57. class ifstream : public istream {
  58. public:
  59. ifstream();
  60. ifstream(const char _HFAR_ *, int =ios::in, int = filebuf::openprot);
  61. ifstream(filedesc);
  62. ifstream(filedesc, char _HFAR_ *, int);
  63. ~ifstream();
  64. streambuf * setbuf(char _HFAR_ *, int);
  65. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  66. void attach(filedesc);
  67. filedesc fd() const { return rdbuf()->fd(); }
  68. int is_open() const { return rdbuf()->is_open(); }
  69. void open(const char _HFAR_ *, int =ios::in, int = filebuf::openprot);
  70. void close();
  71. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  72. };
  73. class ofstream : public ostream {
  74. public:
  75. ofstream();
  76. ofstream(const char _HFAR_ *, int =ios::out, int = filebuf::openprot);
  77. ofstream(filedesc);
  78. ofstream(filedesc, char _HFAR_ *, int);
  79. ~ofstream();
  80. streambuf * setbuf(char _HFAR_ *, int);
  81. filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  82. void attach(filedesc);
  83. filedesc fd() const { return rdbuf()->fd(); }
  84. int is_open() const { return rdbuf()->is_open(); }
  85. void open(const char _HFAR_ *, int =ios::out, int = filebuf::openprot);
  86. void close();
  87. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  88. };
  89. class fstream : public iostream {
  90. public:
  91. fstream();
  92. fstream(const char _HFAR_ *, int, int = filebuf::openprot);
  93. fstream(filedesc);
  94. fstream(filedesc, char _HFAR_ *, int);
  95. ~fstream();
  96. streambuf * setbuf(char _HFAR_ *, int);
  97. filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
  98. void attach(filedesc);
  99. filedesc fd() const { return rdbuf()->fd(); }
  100. int is_open() const { return rdbuf()->is_open(); }
  101. void open(const char _HFAR_ *, int, int = filebuf::openprot);
  102. void close();
  103. int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  104. };
  105. // manipulators to dynamically change file access mode (filebufs only)
  106. inline ios& binary(ios& _fstrm) \
  107. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
  108. inline ios& text(ios& _fstrm) \
  109. { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
  110. // Restore default packing
  111. #pragma pack()
  112. #endif