/* common.c * * Created by Rory Healy (healyr@student.unimelb.edu.au) * Created on 25th August 2021 * Last modified 9th September 2021 * * Contains functions for general use throughout other files. * */ #ifndef COMMON_HEADER #include "common.h" #endif void checkNullPointer(void *ptr) { if (!ptr) { fputs("Error: Cannot allocate memory.\n", stderr); exit(EXIT_FAILURE); } } 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; }