first commit
This commit is contained in:
45
tutils.h
Normal file
45
tutils.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const char* pullArg(int *argc, char** argv[]){
|
||||
if(*argc <= 0)
|
||||
return NULL;
|
||||
(*argc)--;
|
||||
return *argv[0]++;
|
||||
}
|
||||
|
||||
const char *readFile(const char* filename){
|
||||
FILE *fd = fopen(filename, "r");
|
||||
|
||||
fseek(fd, 0, SEEK_END);
|
||||
long size = ftell(fd);
|
||||
rewind(fd);
|
||||
|
||||
char* ret = malloc(size+1);
|
||||
fread(ret, sizeof(char), size, fd);
|
||||
ret[size] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int codeChk(int code, const char* context, const char* error(void)){
|
||||
if(code != 0){
|
||||
if(error != NULL)
|
||||
printf("[%s] -> %s \n", context, error());
|
||||
else
|
||||
printf("[%s]\n", context);
|
||||
exit(0);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void* ptrChk(void* ptr, const char* context, const char* error(void)){
|
||||
if(ptr == NULL){
|
||||
if(error != NULL)
|
||||
printf("[%s] -> %s \n", context, error());
|
||||
else
|
||||
printf("[%s]\n", context);
|
||||
exit(0);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
Reference in New Issue
Block a user