2021-09-08 21:48:00 +10:00
|
|
|
/* common.c
|
|
|
|
*
|
|
|
|
* Created by Rory Healy (healyr@student.unimelb.edu.au)
|
|
|
|
* Created on 25th August 2021
|
2021-09-15 00:06:04 +10:00
|
|
|
* Last modified 14th September 2021
|
2021-09-08 21:48:00 +10:00
|
|
|
*
|
2021-09-15 00:06:04 +10:00
|
|
|
* Contains functions and headers for general use throughout other files.
|
2021-09-08 21:48:00 +10:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMON_HEADER
|
|
|
|
#include "common.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void checkNullPointer(void *ptr) {
|
|
|
|
if (!ptr) {
|
|
|
|
fputs("Error: Cannot allocate memory.\n", stderr);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2021-09-09 17:10:24 +10:00
|
|
|
|
|
|
|
FILE *safeFileOpen(FILE **f, char *fileName, char *mode) {
|
|
|
|
*f = fopen(fileName, mode);
|
|
|
|
if (*f == NULL) {
|
|
|
|
fprintf(stderr, "Error: Unable to open file %s\n", fileName);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
return *f;
|
|
|
|
}
|