Fennel: /home/pub/open/dev/fennel/common/SysCallExcn.cpp Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 #include "fennel/common/CommonPreamble.h" 00025 #include "fennel/common/SysCallExcn.h" 00026 #include "fennel/common/FennelResource.h" 00027 #include <errno.h> 00028 #include 00029 00030 #ifdef MSVC 00031 #include <windows.h> 00032 #endif 00033 00034 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/common/SysCallExcn.cpp#13 $"); 00035 00036 SysCallExcn::SysCallExcn(std::string msgInit) 00037 : FennelExcn(msgInit), errCode(getCurrentErrorCode()) 00038 { 00039 init(); 00040 } 00041 00042 SysCallExcn::SysCallExcn(std::string msgInit, int errCodeInit) 00043 : FennelExcn(msgInit), errCode(errCodeInit) 00044 { 00045 init(); 00046 } 00047 00048 void SysCallExcn::init() 00049 { 00050 std::ostringstream oss; 00051 oss << msg; 00052 oss << ": "; 00053 00054 #ifdef MSVC 00055 oss << "GetLastError() = "; 00056 oss << errCode; 00057 #else 00058 char *pMsg = strerror(errCode); 00059 if (pMsg) { 00060 oss << pMsg; 00061 } else { 00062 oss << "errno = "; 00063 oss << errCode; 00064 } 00065 #endif 00066 msg = oss.str(); 00067 msg = FennelResource::instance().sysCallFailed(msg); 00068 } 00069 00070 00071 int SysCallExcn::getErrorCode() 00072 { 00073 return errCode; 00074 } 00075 00076 int SysCallExcn::getCurrentErrorCode() 00077 { 00078 #ifdef MING32 00079 return GetLastError(); 00080 #else 00081 return errno; 00082 #endif 00083 } 00084 00085 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/common/SysCallExcn.cpp#13 $"); 00086 00087