-
Notifications
You must be signed in to change notification settings - Fork 1
/
HandleErrors.h
59 lines (47 loc) · 1.51 KB
/
HandleErrors.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
/*
File: HandleErrors.h
Version: Error handling functions, with and without setting status
Author: Joe O'Regan
Year 4 Networked Games Assignment
Team 1:
Joe O'Regan K00203642
Samantha Marah K00200782
Jason Foley K00186690
25/11/2017 Added displayErrMoreSpecific() for more detailed error handling
*/
#ifndef __HANDLE_ERRORS
#define __HANDLE_ERRORS
#include <stdio.h> // perror()
/*
Function to display error message and exit
*/
void displayErrMsg(char* reason) {
perror(reason); // Dispay system error message
exit(1); // Exit the program
}
/*
Error message function with exit status
*/
void displayErrMsgStatus(char* reason, int status) {
perror(reason); // Dispay system error message
exit(status); // Exit the program
}
/*
Display a more detailed error message and exit
*/
void displayErrSpecific(char* reason, int status, char* info) {
char* err; // Error message to display to user
sprintf(err, "%s %s", reason, info); // Append the 2 strings to 1 error message
perror(err); // Dispay system error message
exit(status); // Exit the program
}
/*
Display error message for getaddrinfo() when gai_strerror() is used
*/
void displayErrGaiStr(char* reason, int status, int rtnVal ) {
char* err; // Error message to display to user
sprintf(err, "%s %s", reason, gai_strerror(rtnVal)); // Append the 2 strings to 1 error message
perror(err); // Dispay system error message
exit(status); // Exit the program
}
#endif /* __HANDLE_ERRORS */