removed stupid goto in logger

This commit is contained in:
Václav Šmejkal 2024-02-19 12:17:44 +01:00
parent e77937e69e
commit b6bace31e2
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -71,32 +71,29 @@ why2_log_file why2_init_logger(char *directoryPath)
if (buffer > WHY2_MAX_USAGE) //WHY2_MAX_USAGE WAS REACHED if (buffer > WHY2_MAX_USAGE) //WHY2_MAX_USAGE WAS REACHED
{ {
file = INVALID_FILE; file = INVALID_FILE;
} else
goto deallocation;
}
sprintf(filePath, WHY2_LOG_FORMATTING, directoryPath, dateBuffer, buffer); //GENERATE LOG-NAME
file = open(filePath, O_RDWR | O_APPEND | O_CREAT, 0644); //CREATE LOG FILE
//CREATE SYMLINK
sprintf(latestBuffer, WHY2_LOG_LATEST_FORMATTING, directoryPath, WHY2_LOG_LATEST); //GENERATE LATEST.log PATH
latestFilePath = why2_strdup(filePath);
if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS
if (symlink(latestFilePath + (strlen(directoryPath) + 1), latestBuffer) != 0) //CREATE SYMLINK
{ {
if (!why2_get_flags().no_output) fprintf(stderr, "Creating symlink failed!\n"); sprintf(filePath, WHY2_LOG_FORMATTING, directoryPath, dateBuffer, buffer); //GENERATE LOG-NAME
close(file); file = open(filePath, O_RDWR | O_APPEND | O_CREAT, 0644); //CREATE LOG FILE
why2_clean_memory("logger_logfile_init");
return why2_empty_log_file(); //CREATE SYMLINK
sprintf(latestBuffer, WHY2_LOG_LATEST_FORMATTING, directoryPath, WHY2_LOG_LATEST); //GENERATE LATEST.log PATH
latestFilePath = why2_strdup(filePath);
if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS
if (symlink(latestFilePath + (strlen(directoryPath) + 1), latestBuffer) != 0) //CREATE SYMLINK
{
if (!why2_get_flags().no_output) fprintf(stderr, "Creating symlink failed!\n");
close(file);
why2_clean_memory("logger_logfile_init");
return why2_empty_log_file();
}
} }
deallocation:
//DEALLOCATION //DEALLOCATION
why2_deallocate(dateBuffer); why2_deallocate(dateBuffer);
why2_deallocate(latestBuffer); why2_deallocate(latestBuffer);