1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-13 07:55:55 +05:30

reverse-ramdisk.c: fix macro use, include math, improve

This commit is contained in:
Intel A80486DX2-66 2023-12-27 18:33:12 +03:00
parent d303525537
commit a52c6f343c
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -17,6 +17,7 @@ To-Do: error handling on line 167, function fread()
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct {
int ID;
@ -45,12 +46,12 @@ int tf_alloc(size_t n, size_t type_size) {
size_t file_path_len = len_digit + strlen("tf_.tmp");
char* file_path = malloc((file_path_len + 1) * sizeof(char));
if (file_path == NULL) {
fail_line(-2);
line_fail(-2);
return -1;
}
int res = snprintf(file_path, file_path_len, "tf_%zu.tmp", num_temp_files);
if ((size_t) res != file_path_len) {
fail_line(-2);
line_fail(-2);
return -1;
}
@ -157,7 +158,7 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) {
void* data = malloc(data_size);
if (data == NULL) {
fclose(file);
fail_line(-3);
line_fail(-3);
return -1;
}
@ -178,7 +179,7 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) {
printf("Read: ID = %d, data = %016" PRIXPTR ", size = %zu -> '",
ID, (uintptr_t)dest, data_size);
for (size_t i = 0; i < data_size; i++)
printf("0x%02" PRIX8 " ", *((uint8_t*)(dest + i)));
printf("0x%02" PRIX8 " ", *((uint8_t*)((uint8_t*)dest + i)));
printf("'\n");
#endif
return 0;