1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-10 06:42:02 +05:30

reverse-ramdisk.c: put all macros together and move them

This commit is contained in:
Intel A80486DX2-66 2023-12-27 19:11:51 +03:00
parent 015b81fb25
commit 4f396bb3ce
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -19,6 +19,19 @@ To-Do: error handling on line 167, function fread()
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#ifdef DEBUG
# define line_fail(x) do { \
printf("failed on line %d\n", __LINE__ + x); \
} while (0)
#else
# define line_fail(x) do {} while (0)
#endif
#define retreat(s) do { \
perror(s); \
exit(EXIT_FAILURE); \
} while (0)
typedef struct { typedef struct {
int ID; int ID;
char* file_path; char* file_path;
@ -33,14 +46,6 @@ int tf_free(int ID);
int tf_write(int ID, size_t offset, void* data, size_t data_size); int tf_write(int ID, size_t offset, void* data, size_t data_size);
int tf_read(int ID, size_t offset, void* dest, size_t data_size); int tf_read(int ID, size_t offset, void* dest, size_t data_size);
#ifdef DEBUG
# define line_fail(x) do { \
printf("failed on line %d\n", __LINE__ + x); \
} while (0)
#else
# define line_fail(x) do {} while (0)
#endif
int tf_alloc(size_t n, size_t type_size) { int tf_alloc(size_t n, size_t type_size) {
// Create an empty file // Create an empty file
size_t len_digit; size_t len_digit;
@ -190,11 +195,6 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) {
return 0; return 0;
} }
#define retreat(s) do { \
perror(s); \
exit(EXIT_FAILURE); \
} while (0)
#ifdef TEST #ifdef TEST
int main(void) { int main(void) {
int ID = tf_alloc(4, sizeof(int)); int ID = tf_alloc(4, sizeof(int));