mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-25 17:19:46 +05:30
reverse-ramdisk.c: fix file name length, use PRIuMAX for format, flush stdout in debug
This commit is contained in:
parent
2341c7cced
commit
bb43a5dc53
@ -9,7 +9,7 @@ production purposes.
|
|||||||
GCC/Clang/TCC: Compile with -DTEST to set macro TEST as defined, with -DDEBUG
|
GCC/Clang/TCC: Compile with -DTEST to set macro TEST as defined, with -DDEBUG
|
||||||
to enable debug mode
|
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>
|
#include <errno.h>
|
||||||
@ -52,14 +52,15 @@ int tf_alloc(size_t n, size_t type_size) {
|
|||||||
if (num_temp_files == 0)
|
if (num_temp_files == 0)
|
||||||
len_digit = 1;
|
len_digit = 1;
|
||||||
else
|
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");
|
size_t file_path_len = len_digit + strlen("tf_.tmp");
|
||||||
char* file_path = malloc((file_path_len + 1) * sizeof(char));
|
char* file_path = malloc((file_path_len + 1) * sizeof(char));
|
||||||
if (file_path == NULL) {
|
if (file_path == NULL) {
|
||||||
line_fail(-2);
|
line_fail(-2);
|
||||||
return -1;
|
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) {
|
if ((size_t) res != file_path_len) {
|
||||||
line_fail(-2);
|
line_fail(-2);
|
||||||
return -1;
|
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++)
|
for (size_t i = 0; i < data_size; i++)
|
||||||
printf("0x%02" PRIX8 " ", *((uint8_t*)((uint8_t*)dest + i)));
|
printf("0x%02" PRIX8 " ", *((uint8_t*)((uint8_t*)dest + i)));
|
||||||
printf("'\n");
|
printf("'\n");
|
||||||
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user