Files
mrw-cxx/mrw/errno.cpp

62 lines
1.6 KiB
C++
Raw Normal View History

2005-02-08 12:30:22 +00:00
/** @file
$Id$
$Date$
$Author$
@copy © Marc Wäckerlin
@license LGPL, see file <a href="license.html">COPYING</a>
$Log$
2005-02-28 07:29:18 +00:00
Revision 1.3 2005/02/28 07:29:18 marc
added ifdef for non glibc (Solaris)
Revision 1.2 2005/02/18 15:53:07 marc
I'm so stupid, there's strerror for mapping errno to a string...
2005-02-08 12:30:22 +00:00
Revision 1.1 2005/02/08 12:30:22 marc
new in release 1.8.0
1 2 3 4 5 6 7 8
5678901234567890123456789012345678901234567890123456789012345678901234567890
*/
#include <mrw/errno.hpp>
#include <mrw/string.hpp>
2007-08-16 07:43:56 +00:00
#include <mrw/stdext.hpp>
2005-02-08 12:30:22 +00:00
#include <errno.h>
#include <string.h>
2005-02-08 12:30:22 +00:00
2007-08-16 07:43:56 +00:00
mrw::Errno::Errno() throw(): _errnoxxx(errno) {}
2005-02-08 12:30:22 +00:00
mrw::Errno::operator std::string() const throw(std::bad_exception) {
2007-08-16 07:43:56 +00:00
return *this;
2005-02-08 12:30:22 +00:00
}
std::string mrw::Errno::string() const throw(std::bad_exception) {
2007-08-16 07:43:56 +00:00
char* pos(0);
char error[1024];
2007-08-16 07:43:56 +00:00
#ifdef __GLIBC__
# if defined __USE_XOPEN2K && !defined __USE_GNU
return strerror_r(errno=_errnoxxx, error, 1024)!=-1
? error+std::string(" errno=")+_errnoxxx
: std::string("errno=")+_errnoxxx;
# else
return (pos=strerror_r(errno=_errnoxxx, error, 1024))
? pos+std::string(" errno=")+_errnoxxx
: std::string("errno=")+_errnoxxx;
# endif
2005-02-28 07:29:18 +00:00
#else
2007-08-16 07:43:56 +00:00
# if defined __USE_XOPEN2K && !defined __USE_GNU
return strerror_r(errno=_errnoxxx, error, 1024)!=-1
? error+std::string(" errno=")+_errnoxxx
: std::string("errno=")+_errnoxxx;
# else
return (pos=strerror(errno=_errnoxxx))
? error+std::string(" errno=")+_errnoxxx
: std::string("errno=")+_errnoxxx;
# endif
2005-02-28 07:29:18 +00:00
#endif
2005-02-08 12:30:22 +00:00
}