home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / g__~1 / gplibs15.zoo / fstream.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-01  |  2.4 KB  |  120 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #define _STREAM_COMPAT
  19. #include <ioprivat.h>
  20. #include <fstream.h>
  21. #ifdef __GNUG__
  22. #pragma implementation
  23. #endif
  24.  
  25. ifstream::ifstream()
  26. {
  27.     _strbuf = new filebuf();
  28. }
  29.  
  30. ifstream::ifstream(int fd)
  31. {
  32.     _strbuf = new filebuf(fd);
  33. }
  34.  
  35. ifstream::ifstream(const char *name, int mode, int prot)
  36. {
  37.     _strbuf = new filebuf();
  38.     if (!rdbuf()->open(name, mode, prot))
  39.     set(ios::badbit);
  40. }
  41.  
  42. ofstream::ofstream()
  43. {
  44.     _strbuf = new filebuf();
  45. }
  46.  
  47. ofstream::ofstream(int fd)
  48. {
  49.     _strbuf = new filebuf(fd);
  50. }
  51.  
  52. ofstream::ofstream(const char *name, int mode, int prot)
  53. {
  54.     _strbuf = new filebuf();
  55.     if (!rdbuf()->open(name, mode, prot))
  56.     set(ios::badbit);
  57. }
  58.  
  59. #if 0
  60. static int mode_to_sys(enum open_mode mode)
  61. {
  62.     return O_WRONLY;
  63. }
  64.  
  65. static char* fopen_cmd_arg(io_mode i)
  66. {
  67.     return "w";
  68. }
  69. #endif
  70.  
  71. void ifstream::open(const char *name, int mode, int prot)
  72. {
  73.     if (!rdbuf()->open(name, mode, prot))
  74.     set(ios::badbit);
  75. }
  76.  
  77. void ifstream::close()
  78. {
  79.     rdbuf()->close();
  80. }
  81.  
  82. void ofstream::close()
  83. {
  84.     rdbuf()->close();
  85. }
  86.  
  87. void ofstream::open(const char *name, int mode, int prot)
  88. {
  89.     if (!rdbuf()->open(name, mode, prot))
  90.     set(ios::badbit);
  91. }
  92.  
  93. fstream::fstream()
  94. {
  95.     _strbuf = new filebuf();
  96. }
  97.  
  98. fstream::fstream(int fd)
  99. {
  100.     _strbuf = new filebuf(fd);
  101. }
  102.  
  103. fstream::fstream(const char *name, int mode, int prot=0664)
  104. {
  105.     _strbuf = new filebuf();
  106.     if (!rdbuf()->open(name, mode, prot))
  107.     set(ios::badbit);
  108. }
  109.  
  110. void fstream::open(const char *name, int mode, int prot=0664)
  111. {
  112.     if (!rdbuf()->open(name, mode, prot))
  113.     set(ios::badbit);
  114. }
  115.  
  116. void fstream::close()
  117. {
  118.     rdbuf()->close();
  119. }
  120.