82 lines
No EOL
2.1 KiB
C++
82 lines
No EOL
2.1 KiB
C++
// just some random helpers and function I use.
|
|
|
|
#ifndef __M_HELPERS_H__
|
|
#define __M_HELPERS_H__
|
|
|
|
|
|
#ifndef __cplusplus
|
|
#include <stdio.h>
|
|
#define PRINT(message) printf("%s",message)
|
|
#define PRINTE(error) printf("%s",error)
|
|
#else
|
|
#include <iostream>
|
|
#define PRINT(message) std::cout<<message<<"\n";
|
|
#define PRINTE(error) std::cerr<<error<<"\n";
|
|
#endif
|
|
|
|
/*
|
|
* data with a size
|
|
* void pointer with a lenght
|
|
* whatever ya want to call it
|
|
*/
|
|
typedef struct{
|
|
void *data;
|
|
unsigned long length;
|
|
} sizedData;
|
|
|
|
|
|
// FILE IO
|
|
|
|
/*
|
|
* Reads a file and returns a pointer to a null terminated character string
|
|
* don't forget to free!
|
|
* @param {char*} filename the filename (and relative/absolute path) of the file
|
|
*/
|
|
char* readFileC(const char* filename);
|
|
|
|
/*
|
|
* reads a file and returns the raw bytes as a sizedData struct
|
|
* don't forget to free!
|
|
* @param {char*} filename the filename (and relative/absolute path) of the file
|
|
*/
|
|
|
|
sizedData readFileR(const char *filename);
|
|
|
|
/*
|
|
* write a null terminated string to a file
|
|
* @param {char*} filename the filename (and relative/absolute path) of the file
|
|
* @param {char*} data the string to write
|
|
*/
|
|
int writeFileC(const char* filename, char* data);
|
|
|
|
/*
|
|
* write raw data to a file using a sizedData struct
|
|
* @param {char*} filename the filename (and relative/absolute path) of the file
|
|
* @param {sizedData} data the data to write
|
|
*/
|
|
int writeFileR(const char* filename, sizedData data);
|
|
|
|
/* TODO, NOT IMPLEMENTED YET
|
|
* append a null terminated string to a file
|
|
* @param {char*} filename the filename (and relative/absolute path) of the file
|
|
* @param {char*} data the string to append
|
|
*/
|
|
//int appendFileC(char* filename, char* data);
|
|
|
|
/* TODO, NOT IMPLEMENTED YET
|
|
* append raw data to a file using a sizedData struct
|
|
* @param {char*} filename the filename (and relative/absolute path) of the file
|
|
* @param {sizedData} data the data to append
|
|
*/
|
|
//int appendFileR(char* filename, sizedData data);
|
|
|
|
// ERROR HANDLING
|
|
// there is no crash without reason. At least yet.
|
|
|
|
/*
|
|
* crash with a reason
|
|
* @param {char*} reason null terminated string explaining why the program crashed
|
|
*/
|
|
void crash(char* reason);
|
|
|
|
#endif |