-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpf_error.cpp
More file actions
49 lines (46 loc) · 1.33 KB
/
Copy pathpf_error.cpp
File metadata and controls
49 lines (46 loc) · 1.33 KB
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
#include <errno.h>
#include <stdio.h>
#include <iostream>
#include "pf_error.h"
using namespace std;
static const char *PFWarnMsg[] = {
"page pinned in buffer",
"page is not in the buffer",
"invalid page number",
"file open",
"invalid file descriptor (file closed)",
"page already free",
"page already unpinned",
"end of file",
"attempting to resize the buffer too small",
"invalid filename"
};
static const char *PFErrorMsg[] = {
"no memory",
"no buffer space",
"incomplete read of page from file",
"incomplete write of page to file",
"incomplete read of header from file",
"incomplete write of header from file",
"new page to be allocated already in buffer",
"hash table entry not found",
"page already in hash table",
"invalid file name"
};
void PFPrintError(RC rc)
{
// Check the return code is within proper limits
if (rc >= START_PF_WARN && rc <= PF_LASTWARN)
// Print warning
cerr << "PF warning: " << PFWarnMsg[rc - START_PF_WARN] << "\n";
// Error codes are negative, so invert everything
else if (-rc >= -START_PF_ERR && -rc < -PF_LASTERROR)
// Print error
cerr << "PF error: " << PFErrorMsg[-rc + START_PF_ERR] << "\n";
else if (rc == PF_UNIX)
cerr << strerror(errno) << "\n";
else if (rc == 0)
cerr << "PFPrintError called with return code of 0\n";
else
cerr << "PF error: " << rc << " is out of bounds\n";
}