From e7cc090e91b39ff34d75222a21a72d52f2ed6700 Mon Sep 17 00:00:00 2001
From: Jonathan Wakely
@@ -692,6 +693,60 @@
The v2 library included non-standard extensions to construct
+ std::filebuf
s from C stdio types such as
+ FILE*
s and POSIX file descriptors.
+ Today the recommended way to use stdio types with libstdc++-v3
+ IOStreams is via the stdio_filebuf
class (see below),
+ but earlier releases provided slightly different mechanisms.
+
filebuf
s have another ctor with this signature:
+ basic_filebuf(__c_file_type*, ios_base::openmode, int_type);
+ __c_file_type* F
+ // the __c_file_type typedef usually boils down to stdio's FILE
+ ios_base::openmode M
+ // same as all the other uses of openmode
+ int_type B
+ // buffer size, defaults to BUFSIZ if not specified
+ fdopen()
.
+ filebuf
s bring
+ back an old extension: the fd()
member function. The
+ integer returned from this function can be used for whatever file
+ descriptors can be used for on your platform. Naturally, the
+ library cannot track what you do on your own with a file descriptor,
+ so if you perform any I/O directly, don't expect the library to be
+ aware of it.
+ filebuf
constructor and
+ the fd()
function were removed from the standard
+ filebuf. Instead, <ext/stdio_filebuf.h>
contains
+ a derived class called __gnu_cxx::stdio_filebuf
. This
+ class can be constructed from a C FILE*
or a file
+ descriptor, and provides the fd()
function.
+ If you want to access a filebuf
s file descriptor to
+ implement file locking (e.g. using the fcntl()
system
+ call) then you might be interested in Henry Suter's
+ RWLock
+ class.
+
filebuf
s have another ctor with this signature:
- basic_filebuf(__c_file_type*, ios_base::openmode, int_type);
- __c_file_type* F
- // the __c_file_type typedef usually boils down to stdio's FILE
- ios_base::openmode M
- // same as all the other uses of openmode
- int_type B
- // buffer size, defaults to BUFSIZ if not specified
- fdopen()
.
- filebuf
s bring
- back an old extension: the fd()
member function. The
- integer returned from this function can be used for whatever file
- descriptors can be used for on your platform. Naturally, the
- library cannot track what you do on your own with a file descriptor,
- so if you perform any I/O directly, don't expect the library to be
- aware of it.
- filebuf
constructor and
- the fd()
function were removed from the standard
- filebuf. Instead, <ext/stdio_filebuf.h>
contains
- a derived class called __gnu_cxx::stdio_filebuf
.
- filebuf
s to be constructed from
+ stdio types are described in the
+ chapter 27 notes.Return to top of page or to the FAQ.