Created
March 10, 2012 19:49
-
-
Save rajatkhanduja/2012695 to your computer and use it in GitHub Desktop.
Converting a file descriptor to an istream or ostream (with g++-4.5) [ non-portable method ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ext/stdio_filebuf.h> | |
using __gnu_cxx::stdio_filebuf; | |
using std::istream; | |
using std::ostream; | |
inline stdio_filebuf<char> * fileBufFromFD (int fd, std::_Ios_Openmode mode) | |
{ | |
return (new stdio_filebuf<char> (fd, mode)); | |
} | |
istream * createInStreamFromFD (int fd) | |
{ | |
stdio_filebuf<char> * fileBuf = fileBufFromFD (fd, std::ios::in); | |
return (new istream (fileBuf)); | |
} | |
ostream * createOutStreamFromFD (int fd) | |
{ | |
stdio_filebuf<char> * fileBuf = fileBufFromFD (fd, std::ios::out); | |
return (new ostream (fileBuf)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment