-
Notifications
You must be signed in to change notification settings - Fork 1
/
dberror.h
59 lines (47 loc) · 1.48 KB
/
dberror.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef DBERROR_H
#define DBERROR_H
#include "stdio.h"
/* module wide constants */
#define PAGE_SIZE 4096
/* return code definitions */
typedef int RC;
#define RC_OK 0
#define RC_FILE_NOT_FOUND 1
#define RC_FILE_HANDLE_NOT_INIT 2
#define RC_WRITE_FAILED 3
#define RC_READ_NON_EXISTING_PAGE 4
#define RC_RM_COMPARE_VALUE_OF_DIFFERENT_DATATYPE 200
#define RC_RM_EXPR_RESULT_IS_NOT_BOOLEAN 201
#define RC_RM_BOOLEAN_EXPR_ARG_IS_NOT_BOOLEAN 202
#define RC_RM_NO_MORE_TUPLES 203
#define RC_RM_NO_PRINT_FOR_DATATYPE 204
#define RC_RM_UNKOWN_DATATYPE 205
#define RC_IM_KEY_NOT_FOUND 300
#define RC_IM_KEY_ALREADY_EXISTS 301
#define RC_IM_N_TO_LAGE 302
#define RC_IM_NO_MORE_ENTRIES 303
#define RC_TOTALNUMPAGES_GREATEROREQUALTO_NUMOFPAGES 999
#define RC_TOTALMEMSIZE_LESSTHAN_PAGESIZE 998
/* holder for error messages */
extern char *RC_message;
/* print a message to standard out describing the error */
extern void printError (RC error);
extern char *errorMessage (RC error);
#define THROW(rc,message) \
do { \
RC_message=message; \
return rc; \
} while (0) \
// check the return code and exit if it is an error
#define CHECK(code) \
do { \
int rc_internal = (code); \
if (rc_internal != RC_OK) \
{ \
char *message = errorMessage(rc_internal); \
printf("[%s-L%i-%s] ERROR: Operation returned error: %s\n",__FILE__, __LINE__, __TIME__, message); \
free(message); \
exit(1); \
} \
} while(0);
#endif