c-hash-breaker/shared.c
2024-03-02 23:55:03 +01:00

35 lines
855 B
C

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <linux/limits.h>
#include "shared.h"
void safeFree(void **toFree) {
if (*toFree != NULL || *toFree != NULLPTR) {
free(*toFree);
*toFree = NULLPTR;
}
}
void showError(const char *logFilePath_p) {
static char staticLogFilePath[PATH_MAX];
if (logFilePath_p != NULL) {
strlcpy(staticLogFilePath, logFilePath_p, PATH_MAX);
return;
}
if (staticLogFilePath[0] != 0) {
FILE *f = fopen(staticLogFilePath, "a");
if (f == NULL) {
fprintf(stderr, "Impossible d'ouvrir le fichier de log. :\n%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
fprintf(f, "%s\n", strerror(errno));
fclose(f);
return;
}
fprintf(stderr, "%s\n", strerror(errno));
}