error.h 1.63 KB
Newer Older
Bernhard Link's avatar
Bernhard Link committed
1 2
#ifndef REPREPRO_ERROR_H
#define REPREPRO_ERROR_H
Bernhard Link's avatar
Bernhard Link committed
3

Bernhard Link's avatar
Bernhard Link committed
4 5 6 7
#ifndef REPREPRO_GLOBALS_H
#include "globals.h"
#endif

8
bool interrupted(void);
9

Bernhard Link's avatar
Bernhard Link committed
10 11
/* retvalue is simply an int.
 * just named to show it follows the given semantics */
12
/*@numabstract@*/ enum retvalue_enum {
13
	RET_ERROR_INCOMING_DENY = -13,
Bernhard Link's avatar
Bernhard Link committed
14
	RET_ERROR_INTERNAL = -12,
15 16
	RET_ERROR_BZ2 = -11,
	RET_ERROR_Z = -10,
17 18 19 20 21 22 23 24 25 26 27 28 29
	RET_ERROR_INTERRUPTED = -9,
	RET_ERROR_UNKNOWNFIELD = -8,
	RET_ERROR_MISSING = -7,
	RET_ERROR_BADSIG = -6,
	RET_ERROR_GPGME = -5,
	RET_ERROR_EXIST = -4,
	RET_ERROR_OOM = -3,
	RET_ERROR_WRONG_MD5 = -2,
	RET_ERROR = -1,
	RET_NOTHING = 0,
	RET_OK  = 1
};
typedef enum retvalue_enum retvalue;
Bernhard Link's avatar
Bernhard Link committed
30

Bernhard Link's avatar
Bernhard Link committed
31
#define FAILEDTOALLOC(x) unlikely(x == NULL)
32 33 34 35

#define RET_IS_OK(r) likely((r) == RET_OK)
#define RET_WAS_NO_ERROR(r) likely((r) >= (retvalue)0)
#define RET_WAS_ERROR(r) unlikely((r) < (retvalue)0)
Bernhard Link's avatar
Bernhard Link committed
36 37 38

/* update a return value, so that it contains the first error-code
 * and otherwise is RET_OK, if anything was RET_OK */
39
#define RET_UPDATE(ret, update) { if ((update)!=RET_NOTHING && RET_WAS_NO_ERROR(ret)) ret=update;}
Bernhard Link's avatar
Bernhard Link committed
40

41 42
/* like RET_UPDATE, but RET_ENDUPDATE(RET_NOTHING, RET_OK) keeps RET_NOTHING */
#define RET_ENDUPDATE(ret, update) {if (RET_WAS_ERROR(update) && RET_WAS_NO_ERROR(ret)) ret=update;}
Bernhard Link's avatar
Bernhard Link committed
43

Bernhard Link's avatar
Bernhard Link committed
44
/* code a errno in a error */
Bernhard Link's avatar
Bernhard Link committed
45
#define RET_ERRNO(err) ((err>0)?((retvalue)-err):RET_ERROR)
Bernhard Link's avatar
Bernhard Link committed
46 47 48 49 50

/* code a db-error in a error */
// TODO: to be implemented...
#define RET_DBERR(e) RET_ERROR

51
#define ASSERT_NOT_NOTHING(r) {assert (r != RET_NOTHING); if (r == RET_NOTHING) r = RET_ERROR_INTERNAL;}
Bernhard Link's avatar
Bernhard Link committed
52

Bernhard Link's avatar
Bernhard Link committed
53
#define EXIT_RET(ret) (RET_WAS_NO_ERROR(ret)?((nothingiserror&&ret==RET_NOTHING)?EXIT_FAILURE:EXIT_SUCCESS):(int)ret)
Bernhard Link's avatar
Bernhard Link committed
54 55

#endif