exit_error - 1Fr3aK2/Cub3d GitHub Wiki
📝 exit_error
Terminates the program with an error message and performs cleanup of allocated resources.
⚙️ Parameters
| Parameter | Type | Description |
|---|---|---|
data |
t_data * |
Pointer to the main data structure. If not NULL, it will be freed before exiting. |
str |
char * |
Error message to display. If NULL, a generic "Error" message is printed. |
🔁 Returns
| Return value | Description |
|---|---|
void |
The function does not return. The program terminates with exit code 1. |
📖 Description
The exit_error function is used to handle fatal errors in the program. It performs the following steps:
- Prints
"Error\n"ifstrisNULL; otherwise prints the content ofstrto standard error. - If
datais notNULL, callsfree_all(data)to release all the allocated memory and setsdatatoNULL. - Closes all open file descriptors by calling
close_fds(0). - Terminates the program with
exit(1).
This function ensures that all allocated resources are freed and that the program exits cleanly in case of errors.
💡 Example Usage
t_data data;
// Some code that detects a fatal error
if (!map_valid)
{
exit_error(&data, "Invalid map file.");
}