ReactOS  0.4.14-dev-50-g13bb5e2
_Filebuf_base Class Reference

#include <_fstream.h>

Public Member Functions

 _Filebuf_base ()
 
bool _M_open (const char *, ios_base::openmode, long __protection)
 
bool _M_open (const char *, ios_base::openmode)
 
bool _M_open (int __id, ios_base::openmode=ios_base::__default_mode)
 
bool _M_close ()
 
ptrdiff_t _M_read (char *__buf, ptrdiff_t __n)
 
streamoff _M_seek (streamoff __offset, ios_base::seekdir __dir)
 
streamoff _M_file_size ()
 
bool _M_write (char *__buf, ptrdiff_t __n)
 
void_M_mmap (streamoff __offset, streamoff __len)
 
void _M_unmap (void *__mmap_base, streamoff __len)
 
streamoff _M_get_offset (char *__first, char *__last)
 
bool _M_in_binary_mode () const
 
int __o_mode () const
 
bool __is_open () const
 
bool __should_close () const
 
bool __regular_file () const
 
_STLP_fd __get_fd () const
 

Static Public Member Functions

static void _S_initialize ()
 
static size_t _STLP_CALL __page_size ()
 

Protected Attributes

_STLP_fd _M_file_id
 
ios_base::openmode _M_openmode
 
unsigned char _M_is_open
 
unsigned char _M_should_close
 
unsigned char _M_regular_file
 

Static Protected Attributes

static size_t _M_page_size = 4096
 

Detailed Description

Definition at line 55 of file _fstream.h.

Constructor & Destructor Documentation

◆ _Filebuf_base()

_Filebuf_base::_Filebuf_base ( )

Definition at line 153 of file fstream_stdio.cpp.

155  _M_openmode(0),
156  _M_is_open(false),
157  _M_should_close(false)
158 {}
unsigned char _M_should_close
Definition: _fstream.h:123
ios_base::openmode _M_openmode
Definition: _fstream.h:121
unsigned char _M_is_open
Definition: _fstream.h:122
_STLP_fd _M_file_id
Definition: _fstream.h:116
const _STLP_fd INVALID_STLP_FD

Member Function Documentation

◆ __get_fd()

_STLP_fd _Filebuf_base::__get_fd ( ) const
inline

Definition at line 136 of file _fstream.h.

136 { return _M_file_id; }
_STLP_fd _M_file_id
Definition: _fstream.h:116

Referenced by basic_filebuf< char, char_traits< char > >::fd().

◆ __is_open()

bool _Filebuf_base::__is_open ( ) const
inline

Definition at line 133 of file _fstream.h.

133 { return (_M_is_open !=0 ); }
unsigned char _M_is_open
Definition: _fstream.h:122

Referenced by basic_filebuf< char, char_traits< char > >::is_open().

◆ __o_mode()

int _Filebuf_base::__o_mode ( ) const
inline

Definition at line 132 of file _fstream.h.

132 { return (int)_M_openmode; }
ios_base::openmode _M_openmode
Definition: _fstream.h:121

◆ __page_size()

static size_t _STLP_CALL _Filebuf_base::__page_size ( )
inlinestatic

Definition at line 131 of file _fstream.h.

131 { return _M_page_size; }
static size_t _M_page_size
Definition: _fstream.h:113

◆ __regular_file()

bool _Filebuf_base::__regular_file ( ) const
inline

Definition at line 135 of file _fstream.h.

135 { return (_M_regular_file != 0); }
unsigned char _M_regular_file
Definition: _fstream.h:124

◆ __should_close()

bool _Filebuf_base::__should_close ( ) const
inline

Definition at line 134 of file _fstream.h.

134 { return (_M_should_close != 0); }
unsigned char _M_should_close
Definition: _fstream.h:123

◆ _M_close()

bool _Filebuf_base::_M_close ( )

Definition at line 338 of file fstream_stdio.cpp.

339 {
340  if (!_M_is_open)
341  return false;
342 
343  bool ok = _M_should_close ? (fclose(_M_file) == 0) : true;
344 
345  _M_is_open = _M_should_close = false;
346  _M_openmode = 0;
347  return ok;
348 }
unsigned char _M_should_close
Definition: _fstream.h:123
ios_base::openmode _M_openmode
Definition: _fstream.h:121
unsigned char _M_is_open
Definition: _fstream.h:122
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define ok(value,...)
Definition: atltest.h:57

◆ _M_file_size()

streamoff _Filebuf_base::_M_file_size ( )

Definition at line 167 of file fstream_stdio.cpp.

168 {
170 }
static streamoff __file_size(_STLP_fd fd)
#define _STLP_PRIV
Definition: _dm.h:70
_STLP_fd _M_file_id
Definition: _fstream.h:116

Referenced by _M_seek().

◆ _M_get_offset()

streamoff _Filebuf_base::_M_get_offset ( char __first,
char __last 
)
inline

Definition at line 88 of file _fstream.h.

88  {
89 #if defined (_STLP_UNIX) || defined (_STLP_MAC)
90  return __last - __first;
91 #else // defined (_STLP_WIN32)
92  return ( (_M_openmode & ios_base::binary) != 0 )
93  ? (__last - __first)
94  : count(__first, __last, '\n') + (__last - __first);
95 #endif
96  }
GLuint GLuint GLsizei count
Definition: gl.h:1545
ios_base::openmode _M_openmode
Definition: _fstream.h:121
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
const GLuint GLenum const GLvoid * binary
Definition: glext.h:7538

◆ _M_in_binary_mode()

bool _Filebuf_base::_M_in_binary_mode ( ) const
inline

Definition at line 100 of file _fstream.h.

100  {
101 #if defined (_STLP_UNIX) || defined (_STLP_MAC) || defined(__BEOS__) || defined (__amigaos__)
102  return true;
103 #elif defined (_STLP_WIN32) || defined (_STLP_VM)
104  return (_M_openmode & ios_base::binary) != 0;
105 #else
106 # error "Port!"
107 #endif
108  }
ios_base::openmode _M_openmode
Definition: _fstream.h:121
const GLuint GLenum const GLvoid * binary
Definition: glext.h:7538

◆ _M_mmap()

void * _Filebuf_base::_M_mmap ( streamoff  __offset,
streamoff  __len 
)

Definition at line 412 of file fstream_stdio.cpp.

413 {
414  return 0;
415 }

◆ _M_open() [1/3]

bool _Filebuf_base::_M_open ( const char name,
ios_base::openmode  openmode,
long  __protection 
)

Definition at line 172 of file fstream_stdio.cpp.

174 {
175  _STLP_fd file_no;
176 
177  if (_M_is_open)
178  return false;
179 
180  // use FILE-based i/o
181  const char* flags;
182 
183  switch (openmode & (~ios_base::ate)) {
184  case ios_base::out:
186  flags = "w";
187  break;
188 
191  flags = "wb";
192  break;
193 
194  case ios_base::out | ios_base::app:
195  flags = "a";
196  break;
197 
198  case ios_base::out | ios_base::app | ios_base::binary:
199  flags = "ab";
200  break;
201 
202  case ios_base::in:
203  flags = "r";
204  break;
205 
207  flags = "rb";
208  break;
209 
211  flags = "r+";
212  break;
213 
215  flags = "r+b";
216  break;
217 
219  flags = "w+";
220  break;
221 
223  flags = "w+b";
224  break;
225 
226  default: // The above are the only combinations of
227  return false; // flags allowed by the C++ standard.
228  }
229 
230  // fbp : TODO : set permissions !
231  (void)permission; // currently unused //*TY 02/26/2000 - added to suppress warning message
232  _M_file = FOPEN(name, flags);
233 
234  if (_M_file) {
235  file_no = fileno(_M_file);
236  } else {
237  return false;
238  }
239 
240  // unset buffering immediately
241  setbuf(_M_file, 0);
242 
243  _M_is_open = true;
244 
245  if (openmode & ios_base::ate) {
246  if (FSEEK(_M_file, 0, SEEK_END) != 0)
247  _M_is_open = false;
248  }
249 
250  _M_file_id = file_no;
252  _M_openmode = openmode;
253 
254  if (_M_is_open)
256 
257  return (_M_is_open != 0);
258 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
unsigned char _M_regular_file
Definition: _fstream.h:124
unsigned char _M_should_close
Definition: _fstream.h:123
double __cdecl trunc(double)
ios_base::openmode _M_openmode
Definition: _fstream.h:121
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
static FILE * out
Definition: regtests2xml.c:44
const GLuint GLenum const GLvoid * binary
Definition: glext.h:7538
GLbitfield flags
Definition: glext.h:7161
#define FSEEK
#define _STLP_PRIV
Definition: _dm.h:70
unsigned char _M_is_open
Definition: _fstream.h:122
GLuint in
Definition: glext.h:9616
Definition: name.c:36
_STLP_fd _M_file_id
Definition: _fstream.h:116
#define SEEK_END
Definition: cabinet.c:27
_CRTIMP void __cdecl setbuf(_Inout_ FILE *_File, _Inout_updates_opt_(BUFSIZ) _Post_readable_size_(0) char *_Buffer)
#define FOPEN
static _STLP_MOVE_TO_PRIV_NAMESPACE bool __is_regular_file(_STLP_fd fd)

Referenced by _M_open(), basic_filebuf< char, char_traits< char > >::_M_open(), and basic_filebuf< char, char_traits< char > >::open().

◆ _M_open() [2/3]

bool _Filebuf_base::_M_open ( const char name,
ios_base::openmode  openmode 
)

Definition at line 261 of file fstream_stdio.cpp.

262 {
263  // This doesn't really grant everyone in the world read/write
264  // access. On Unix, file-creation system calls always clear
265  // bits that are set in the umask from the permissions flag.
266  return this->_M_open(name, openmode, S_IRUSR | S_IWUSR | S_IRGRP |
267  S_IWGRP | S_IROTH | S_IWOTH);
268 }
#define S_IRGRP
Definition: propsheet.h:41
#define S_IWGRP
Definition: propsheet.h:45
#define S_IWUSR
Definition: propsheet.h:33
#define S_IROTH
Definition: propsheet.h:53
#define S_IWOTH
Definition: propsheet.h:57
#define S_IRUSR
Definition: propsheet.h:29
bool _M_open(const char *, ios_base::openmode, long __protection)
Definition: name.c:36

◆ _M_open() [3/3]

bool _Filebuf_base::_M_open ( int  __id,
ios_base::openmode  init_mode = ios_base::__default_mode 
)

Definition at line 273 of file fstream_stdio.cpp.

274 {
275  if (_M_is_open || file_no < 0)
276  return false;
277 
278  struct STAT buf;
279  if (FSTAT(file_no, &buf) != 0)
280  return false;
281  int mode = buf.st_mode;
282 
283  switch ( mode & (S_IWRITE | S_IREAD) ) {
284  case S_IREAD:
286  break;
287  case S_IWRITE:
289  break;
290  case (S_IWRITE | S_IREAD):
292  break;
293  default:
294  return false;
295  }
296  _M_file_id = file_no;
297  _M_is_open = true;
298  _M_should_close = false;
300  return true;
301 }
unsigned char _M_regular_file
Definition: _fstream.h:124
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
unsigned char _M_should_close
Definition: _fstream.h:123
ios_base::openmode _M_openmode
Definition: _fstream.h:121
static FILE * out
Definition: regtests2xml.c:44
#define _STLP_PRIV
Definition: _dm.h:70
unsigned char _M_is_open
Definition: _fstream.h:122
#define FSTAT
GLenum mode
Definition: glext.h:6217
#define S_IREAD
Definition: acwin.h:113
#define S_IWRITE
Definition: acwin.h:114
GLuint in
Definition: glext.h:9616
_STLP_fd _M_file_id
Definition: _fstream.h:116
#define STAT
static _STLP_MOVE_TO_PRIV_NAMESPACE bool __is_regular_file(_STLP_fd fd)

◆ _M_read()

ptrdiff_t _Filebuf_base::_M_read ( char __buf,
ptrdiff_t  __n 
)

Definition at line 352 of file fstream_stdio.cpp.

352  {
353  return fread(buf, 1, n, _M_file);
354 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLdouble n
Definition: glext.h:7729
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)

◆ _M_seek()

streamoff _Filebuf_base::_M_seek ( streamoff  __offset,
ios_base::seekdir  __dir 
)

Definition at line 377 of file fstream_stdio.cpp.

378 {
379  int whence;
380 
381  switch ( dir ) {
382  case ios_base::beg:
384  return streamoff(-1);
385  whence = SEEK_SET;
386  break;
387  case ios_base::cur:
388  whence = SEEK_CUR;
389  break;
390  case ios_base::end:
391  if (/* offset > 0 || */ -offset > _M_file_size() )
392  return streamoff(-1);
393  whence = SEEK_END;
394  break;
395  default:
396  return streamoff(-1);
397  }
398 
399  if ( FSEEK(_M_file, offset, whence) == 0 ) {
400  return FTELL(_M_file);
401  }
402 
403  return streamoff(-1);
404 }
off_t streamoff
Definition: char_traits.h:74
#define SEEK_CUR
Definition: util.h:63
#define FTELL
GLintptr offset
Definition: glext.h:5920
GLuint GLuint end
Definition: gl.h:1545
streamoff _M_file_size()
unsigned int dir
Definition: maze.c:112
#define SEEK_SET
Definition: jmemansi.c:26
#define FSEEK
#define SEEK_END
Definition: cabinet.c:27

◆ _M_unmap()

void _Filebuf_base::_M_unmap ( void __mmap_base,
streamoff  __len 
)

Definition at line 417 of file fstream_stdio.cpp.

418 {
419  // precondition : there is a valid mapping at the moment
420 }

◆ _M_write()

bool _Filebuf_base::_M_write ( char __buf,
ptrdiff_t  __n 
)

Definition at line 358 of file fstream_stdio.cpp.

359 {
360  for (;;) {
361  ptrdiff_t written = fwrite(buf, 1, n, _M_file);
362 
363  if (n == written) {
364  return true;
365  }
366 
367  if (written > 0 && written < n) {
368  n -= written;
369  buf += written;
370  } else {
371  return false;
372  }
373  }
374 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLdouble n
Definition: glext.h:7729
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247

Referenced by basic_filebuf< char, char_traits< char > >::_M_write().

◆ _S_initialize()

void _Filebuf_base::_S_initialize ( )
static

Definition at line 160 of file fstream_stdio.cpp.

161 {
162 
163 }

Referenced by ios_base::Init::Init().

Member Data Documentation

◆ _M_file_id

_STLP_fd _Filebuf_base::_M_file_id
protected

Definition at line 116 of file _fstream.h.

Referenced by _M_file_size(), and _M_open().

◆ _M_is_open

unsigned char _Filebuf_base::_M_is_open
protected

Definition at line 122 of file _fstream.h.

Referenced by _M_close(), and _M_open().

◆ _M_openmode

ios_base::openmode _Filebuf_base::_M_openmode
protected

Definition at line 121 of file _fstream.h.

Referenced by _M_close(), and _M_open().

◆ _M_page_size

_STLP_MOVE_TO_STD_NAMESPACE size_t _Filebuf_base::_M_page_size = 4096
staticprotected

Definition at line 113 of file _fstream.h.

◆ _M_regular_file

unsigned char _Filebuf_base::_M_regular_file
protected

Definition at line 124 of file _fstream.h.

Referenced by _M_open().

◆ _M_should_close

unsigned char _Filebuf_base::_M_should_close
protected

Definition at line 123 of file _fstream.h.

Referenced by _M_close(), and _M_open().


The documentation for this class was generated from the following files: