1 |
// Spectre 2 |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#ifndef _Error_hpp_ |
8 |
#define _Error_hpp_ |
9 |
|
10 |
#include "menes/platform.hpp" |
11 |
|
12 |
#ifdef MENES_PRAGMA_ONCE |
13 |
#pragma once |
14 |
#endif |
15 |
|
16 |
#include <menes-api/error.hpp> |
17 |
|
18 |
#include <errno.h> |
19 |
|
20 |
struct MENES_DECLARE ApiTraits : public api::ErrorTraits<int> |
21 |
{ |
22 |
static const unsigned ErrorBase = 10; |
23 |
static const char* GetName() { return "SMBC"; } |
24 |
static ErrorCode GetLastError() { return errno; } |
25 |
static ext::String GetMessage(const ErrorCode& code) |
26 |
{ |
27 |
char buffer[1024]; |
28 |
|
29 |
#ifdef __GNUC__ |
30 |
return ext::Buffer(::strerror_r(code, buffer, sizeof (buffer))); |
31 |
#else |
32 |
api::Posix::CheckError(::strerror_r(code, buffer, sizeof (buffer))); |
33 |
#endif |
34 |
|
35 |
return ext::Buffer(buffer); |
36 |
} |
37 |
}; |
38 |
|
39 |
MENES_DECLARE typedef api::ErrorImpl<ApiTraits> Error; |
40 |
|
41 |
_finline int CheckError(int status) |
42 |
{ |
43 |
if (status < 0) |
44 |
throw Error(); |
45 |
return status; |
46 |
} |
47 |
|
48 |
#endif//_Error_hpp_ |