-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherrors.c
57 lines (53 loc) · 1.71 KB
/
errors.c
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
#include "errors.h"
#include <stdio.h> //fprintf
#include <stdlib.h> //exit
#ifdef _WIN32
# define ENDL "\r\n"
#else
# define ENDL "\n"
#endif
#define ERR stderr
#define pe(M, ...) fprintf(ERR, "[ERROR]: " M, ##__VA_ARGS__)
#define fargs(A) ((A) ? *((char const **)(A)) : "_output_file_")
#define margs(A) ((A) ? *((char const **)(A)) : "")
int handle_error(int error_number, const void* args) {
switch (error_number) {
case ERR_FOPEN:
pe("Couldn't open file %s" ENDL, fargs(args));
exit(error_number);
break;
case ERR_MEM:
pe("Couldn't allocate memory %s" ENDL, margs(args));
exit(error_number);
break;
case ERR_BWRITE:
pe("Writing to the output file: %s" ENDL, fargs(args));
break;
case ERR_BREAD:
pe("Unable to read from the output file: %s" ENDL, fargs(args));
break;
case ERR_PACKET_ADD:
pe("An error occured when trying to reallocate memory for the "
"hold %s" ENDL, margs(args));
exit(error_number);
break;
case ERR_PACKING:
pe("An error occured while trying to pack the packet" ENDL);
break;
case ERR_CONNECTION:
pe("An error occurred trying create the socket" ENDL);
break;
case ERR_INVALID:
pe("An invalid (not corrupt) fountain was send to the program");
break;
case ERR_MAP:
pe("Couldn't map file %s" ENDL, fargs(args));
break;
case ERR_SEND:
pe("An error occurred sending");
break;
default:
return 0;
}
return error_number;
}