1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-24 22:59:49 +05:30

reverse-ramdisk.c: fix file name length, use PRIuMAX for format, flush stdout in debug

This commit is contained in:
Intel A80486DX2-66 2023-12-27 21:29:16 +03:00
parent 2341c7cced
commit bb43a5dc53
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -9,7 +9,7 @@ production purposes.
GCC/Clang/TCC: Compile with -DTEST to set macro TEST as defined, with -DDEBUG
to enable debug mode
To-Do: error handling on line 167, function fread()
To-Do: error handling on line 179, function fread()
*/
#include <errno.h>
@ -52,14 +52,15 @@ int tf_alloc(size_t n, size_t type_size) {
if (num_temp_files == 0)
len_digit = 1;
else
len_digit = (size_t) log((double) num_temp_files + 1.) / log(10.);
len_digit = (size_t) ceil(log((double) num_temp_files + 1.) / log(10.));
size_t file_path_len = len_digit + strlen("tf_.tmp");
char* file_path = malloc((file_path_len + 1) * sizeof(char));
if (file_path == NULL) {
line_fail(-2);
return -1;
}
int res = snprintf(file_path, file_path_len, "tf_%zu.tmp", num_temp_files);
int res = snprintf(file_path, file_path_len, "tf_%" PRIuMAX ".tmp",
(uintmax_t) num_temp_files);
if ((size_t) res != file_path_len) {
line_fail(-2);
return -1;
@ -191,6 +192,7 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) {
for (size_t i = 0; i < data_size; i++)
printf("0x%02" PRIX8 " ", *((uint8_t*)((uint8_t*)dest + i)));
printf("'\n");
fflush(stdout);
#endif
return 0;
}