Portable file I/O with system error codes support

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Portable file I/O with system error codes support

Boost - Users mailing list
Hi,

I'm looking for a portable way to open a file, read some data from it,
and do a proper error reporting in case of error.

Apparently std::fstream is not suitable for this task because it does
not provide means to retrieve original error code or even some human
readable description of what went wrong (checking errno does not count
since the standard does not guarantee it is set by any functions in
std::fstream).

I'm wondering if boost::iostreams can do that, but I've found nothing
this far that could help in getting the error code. I've also tried
boost::filesystem::fstream, but no luck.

Users of large frameworks like Qt have advantage of their portable
wrappers for file I/O like QFile. Are there any means in Boost which
provide similar functionality?

Related StackOverflow question:
https://stackoverflow.com/questions/45840686/portable-way-to-read-a-file-in-c-and-handle-possible-errors

Thanks.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Portable file I/O with system error codes support

Boost - Users mailing list
Beast has a cross platform File API:
--
Follow me on GitHub: https://github.com/vinniefalco

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Portable file I/O with system error codes support

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
> I'm looking for a portable way to open a file, read some data from it,
> and do a proper error reporting in case of error.

Literally https://ned14.github.io/afio/index.html

It's the post Boost peer review design after a peer review here in
August 2015. It looks to have some legs as part of a future C++
standardised replacement i/o layer for iostreams, Intel just very kindly
made available to me their Optane storage devices so I can tune AFIO v2
for them. I am currently (re)porting AFIO to FreeBSD and libc++
specifically for the Optane trials.

> Apparently std::fstream is not suitable for this task because it does
> not provide means to retrieve original error code or even some human
> readable description of what went wrong (checking errno does not count
> since the standard does not guarantee it is set by any functions in
> std::fstream).

The original error code is preserved on all platforms. So, on Windows,
that's the NT kernel error code if a NT kernel function was used. You
can use the C++ 11 STL mechanism of error conditions to compare the
original error code against any std::errc::* generic error condition,
and apart from bugs some of which stem from Microsoft's incorrect
mapping, it should work.

Niall

--
ned Productions Limited Consulting
http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users