00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025
00026
00027 #include <string>
00028 #include <iostream>
00029 #include <sstream>
00030 #include <iomanip>
00031
00032 using std::ostringstream;
00033 using std::string;
00034 using std::endl;
00035 using std::ends;
00036 using std::cerr;
00037
00038
00039
00040 #include <errno.h>
00041 #include <string.h>
00042
00043
00044
00045 #include "error.h"
00046
00047 void real_fail_neg( int eval, const char *eval_str, const char *func, const char *file, int line )
00048 {
00049 if ( eval < 0 )
00050 {
00051 string exc;
00052 ostringstream sb;
00053
00054 sb << file << ":" << line << ": In function \"" << func << "\": \"" << eval_str << "\" evaluated to " << eval;
00055 if ( errno != 0 )
00056 sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
00057 sb << ends;
00058 exc = sb.str();
00059 cerr << exc << endl;
00060 throw exc;
00061 }
00062 }
00063
00064
00072 void real_fail_null( const void *eval, const char *eval_str, const char *func, const char *file, int line )
00073 {
00074 if ( eval == NULL )
00075 {
00076
00077 string exc;
00078 ostringstream sb;
00079
00080 sb << file << ":" << line << ": In function \"" << func << "\": " << eval_str << " is NULL" << ends;
00081 exc = sb.str();
00082 cerr << exc << endl;
00083 throw exc;
00084 }
00085 }
00086
00087
00088 void real_fail_if( bool eval, const char *eval_str, const char *func, const char *file, int line )
00089 {
00090 if ( eval == true )
00091 {
00092
00093 string exc;
00094 ostringstream sb;
00095
00096 sb << file << ":" << line << ": In function \"" << func << "\": condition \"" << eval_str << "\" is true";
00097 if ( errno != 0 )
00098 sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
00099 sb << ends;
00100 exc = sb.str();
00101 cerr << exc << endl;
00102 throw exc;
00103 }
00104 }