From 888b257a7b37325e00995ddaf46cc8b15cd96d56 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Wed, 3 Jan 2024 21:21:29 +0300 Subject: [PATCH] reverse-ramdisk.c: convert macro names to upper case --- c-programming/reverse-ramdisk.c | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/c-programming/reverse-ramdisk.c b/c-programming/reverse-ramdisk.c index 5be9380..983e71e 100644 --- a/c-programming/reverse-ramdisk.c +++ b/c-programming/reverse-ramdisk.c @@ -29,12 +29,12 @@ To-Do: Add thread-safe versions of functions (use postfix `_r`) #endif #ifdef DEBUG -# define line_fail(x) printf("failed on line %d\n", __LINE__ + x) +# define LINE_FAIL(x) printf("failed on line %d\n", __LINE__ + x) #else -# define line_fail(x) +# define LINE_FAIL(x) #endif -#define retreat(s) do { \ +#define RETREAT(s) do { \ perror(s); \ exit(EXIT_FAILURE); \ } while (0) @@ -68,13 +68,13 @@ 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) { - line_fail(-2); + LINE_FAIL(-2); return -1; } int res = snprintf(file_path, file_path_len + 1, "tf_%" PRIuMAX ".tmp", (uintmax_t) num_temp_files); if ((size_t) res != file_path_len) { - line_fail(-2); + LINE_FAIL(-2); return -1; } @@ -85,14 +85,14 @@ int tf_alloc(size_t n, size_t type_size) { FILE* file = fopen(file_path, "w+b"); if (file == NULL) { #endif - line_fail(-2); + LINE_FAIL(-2); return -1; } // Allocate memory for the TempFile struct TempFile* temp_file = malloc(sizeof(TempFile)); if (temp_file == NULL) { - line_fail(-2); + LINE_FAIL(-2); return -1; } @@ -109,7 +109,7 @@ int tf_alloc(size_t n, size_t type_size) { temp_files = realloc(temp_files, (size_t) num_temp_files * sizeof(TempFile)); if (temp_files == NULL) { - line_fail(-2); + LINE_FAIL(-2); return -1; } @@ -136,7 +136,7 @@ int tf_free(int ID) { // Delete the file if (remove(temp_files[index].file_path) != 0) { - line_fail(-1); + LINE_FAIL(-1); return -1; } @@ -150,7 +150,7 @@ int tf_free(int ID) { if (--num_temp_files > 0) { if ((temp_files = realloc(temp_files, num_temp_files * sizeof(TempFile))) == NULL) { - line_fail(-2); + LINE_FAIL(-2); return -1; } } @@ -186,7 +186,7 @@ int tf_write(int ID, size_t offset, void* src, size_t data_size) { #else if (fseek(file, offset, SEEK_SET) == -1) { #endif - line_fail(-1); + LINE_FAIL(-1); return -1; } @@ -208,7 +208,7 @@ int tf_write(int ID, size_t offset, void* src, size_t data_size) { #if IS_POSIX if (fsync(file) == -1) { - line_fail(-1); + LINE_FAIL(-1); return -1; } #else @@ -246,7 +246,7 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) { #else fclose(file); #endif - line_fail(-7); + LINE_FAIL(-7); return -1; } @@ -257,7 +257,7 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) { #else if (fseek(file, offset, SEEK_SET) == -1) { #endif - line_fail(-1); + LINE_FAIL(-1); return -1; } @@ -298,13 +298,13 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) { int main(void) { int ID = tf_alloc(4, sizeof(int)); if (ID == -1) - retreat("tf_alloc"); + RETREAT("tf_alloc"); int test_data[4] = {123, 456, 789, -123}; for (size_t i = 0; i < 4; i++) if (tf_write(ID, i * sizeof(int), &test_data[i], sizeof(int)) == -1) - retreat("tf_write"); + RETREAT("tf_write"); // round-trip test_data[0] = 111; @@ -314,7 +314,7 @@ int main(void) { for (size_t i = 0; i < 4; i++) if (tf_read(ID, i * sizeof(int), &test_data[i], sizeof(int)) == -1) - retreat("tf_read"); + RETREAT("tf_read"); printf("Values: %d %d %d %d\n", test_data[0], test_data[1], test_data[2], test_data[3]);