-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommon.cc
More file actions
29 lines (26 loc) · 877 Bytes
/
common.cc
File metadata and controls
29 lines (26 loc) · 877 Bytes
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
#include <cstdlib>
#include "common.hh"
/** \brief Opens a file and checks the operation was successful.
*
* Opens a file, and checks the return value to ensure that the operation
* was successful.
* \param[in] filename the file to open.
* \param[in] mode the cstdio fopen mode to use.
* \return The file handle. */
FILE* safe_fopen(const char* filename,const char* mode) {
FILE *temp=fopen(filename,mode);
if(temp==NULL) {
fprintf(stderr,"Error opening file \"%s\"\n",filename);
exit(1);
}
return temp;
}
/** \brief Function for printing fatal error messages and exiting.
*
* Function for printing fatal error messages and exiting.
* \param[in] p a pointer to the message to print.
* \param[in] status the status code to return with. */
void fatal_error(const char *p,int code) {
fprintf(stderr,"Error: %s\n",p);
exit(code);
}