Constructing a C fstream from a POSIX File Descriptor
This inquiry presents a seemingly straightforward task that proves to be complex: constructing a C fstream from a POSIX file descriptor. Does the solution lie in a simpler approach or is there a suitable library available?
The Complexity of the Issue
According to experts, there is no standard C mechanism for this task. However, some implementations of the standard library, such as libstdc , offer non-standard extensions.
Non-Standard Solutions
The following non-standard solutions are available:
libstdc :
__gnu_cxx::stdio_filebuf<char> filebuf(posix_handle, std::ios::in); istream is(&filebuf);
Microsoft Visual C :
ifstream ifs(::_fdopen(posix_handle, "r"));
Conclusion
While there is no standard C method for this task, non-standard extensions provided by specific implementations offer viable solutions.
The above is the detailed content of How Can I Create a C fstream from a POSIX File Descriptor?. For more information, please follow other related articles on the PHP Chinese website!