Skip to content
Snippets Groups Projects
Commit 40dd54a5 authored by Radovan Červený's avatar Radovan Červený
Browse files

changed fdstream documentation, added FAIL_FD constant, fallback file descriptor is now optional

parent f3833379
No related branches found
No related tags found
1 merge request!14BP_cervera3 - new measurements
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
   
namespace std { namespace std {
   
const int FAIL_FD = -1;
fdstreambuf::fdstreambuf ( int fd ) : fd ( fd ) { fdstreambuf::fdstreambuf ( int fd ) : fd ( fd ) {
setp ( buff.begin ( ), buff.end ( ) - 1 ); setp ( buff.begin ( ), buff.end ( ) - 1 );
} }
...@@ -61,7 +63,7 @@ bool fdaccessor::is_redirected ( ) const { ...@@ -61,7 +63,7 @@ bool fdaccessor::is_redirected ( ) const {
return redirected; return redirected;
} }
   
ofdstream::ofdstream ( int fd, int fallback_fd ) : fda ( fd, fallback_fd ), fdbuf ( fda.get_fd ( ) ) { ofdstream::ofdstream ( int fd, int fallback_fd = FAIL_FD) : fda ( fd, fallback_fd ), fdbuf ( fda.get_fd ( ) ) {
this->init ( & fdbuf ); this->init ( & fdbuf );
   
if ( fda.get_fd ( ) == -1 ) if ( fda.get_fd ( ) == -1 )
......
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
   
/* /*
* ofdstream * ofdstream
* ofdstream takes a file descriptor (fd) by constructor to use for output * ofdstream takes a primary file descriptor (fd) and fallback file descriptor by constructor to use for output
* if the file descriptor is not valid for any reason during construction of the ofdstream, ofdstream will set its state to ios::fail * if the primary fd is not valid for any reason, ofdstream will try to use fallback fd, if even fallback fd is not valid, ofdstream sets its state to ios::fail
* if the file descriptor is valid, it is used for successive buffered output * if the primary fd (or fallback fd) is valid , it is used for successive buffered output
* *
* supplied file descriptor has to be already open in order for ofdstream to work * supplied file descriptor has to be already open in order for ofdstream to work
* ofdstream does not close the file descriptor and does not change internal flags of the file descriptor during the lifetime of ofdstream and during destruction of ofdstream * ofdstream does not close the file descriptor and does not change internal flags of the file descriptor during the lifetime of ofdstream and during destruction of ofdstream
*
* typical use is to use as primary fd some arbitrary fd (5) and for fallback fd some standard fd (2) if we wish to see the output
*/ */
   
#ifndef FDSTREAM_HPP_ #ifndef FDSTREAM_HPP_
...@@ -22,6 +24,8 @@ ...@@ -22,6 +24,8 @@
   
namespace std { namespace std {
   
extern const int FAIL_FD;
class fdstreambuf : public streambuf { class fdstreambuf : public streambuf {
static const size_t buff_sz = 512; static const size_t buff_sz = 512;
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment