check_map_name - 1Fr3aK2/Cub3d GitHub Wiki

📝 check_map_name

This function validates a map file name before it is used by the program. It ensures that the file exists, can be opened, and has the correct .cub extension. If any check fails, the program exits with an error message.

⚙️ Parameters

Parameter Type Description
file_name char * Pointer to the string containing the map file name to validate.

📖 Behavior

Behavior Description
Null pointer check If file_name is NULL, calls exit_error with a message about an invalid pointer.
File existence Tries to open the file in read-only mode. If it fails, calls exit_error.
Extension validation Checks that the file name is at least 4 characters and ends with .cub. If not, calls exit_error.
Cleanup Closes the file descriptor after validation.

🔁 Return

Return Description
void The function does not return. If validation fails, it exits the program.

💡 Usage Notes

  • check_map_name should be called before any attempt to read or parse the map file.
  • Ensures that the program only works with valid .cub map files, preventing runtime errors due to invalid or inaccessible files.
  • Relies on exit_error to handle all error conditions and terminate the program gracefully.