1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-28 00:00:18 +05:30

C: reverse-ramdisk.c: make use of ternary operator

This commit is contained in:
Intel A80486DX2-66 2024-02-22 20:29:14 +03:00
parent 544ae06944
commit 9c47cde541
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -80,12 +80,12 @@ int tf_alloc(size_t n, size_t type_size) {
DBG_PRINT("tf_alloc(%zu, %zu)\n", n, type_size);
// Create an empty file
size_t len_digit;
if (num_temp_files == 0)
len_digit = 1;
else
len_digit = (size_t) floor(log10((double) num_temp_files)) + 1;
size_t file_path_len = len_digit + strlen("tf_.tmp");
size_t len_digit =
num_temp_files == 0 ?
1
:
(size_t) floor(log10((double) num_temp_files)) + 1,
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);
@ -123,10 +123,10 @@ int tf_alloc(size_t n, size_t type_size) {
temp_file->file = file;
// Allocate/reallocate memory for the temp_files structure
if (temp_files == NULL)
temp_files = malloc(sizeof(TempFile));
else
temp_files = realloc(temp_files, num_temp_files * sizeof(TempFile));
temp_files = temp_files == NULL ?
malloc(sizeof(TempFile))
:
realloc(temp_files, num_temp_files * sizeof(TempFile));
if (temp_files == NULL) {
LINE_FAIL(-2);
return -1;