set_error_handler.c 748 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <grass/gis.h>
  2. #include <grass/vector.h>
  3. struct handler_input
  4. {
  5. struct Map_info *Map;
  6. dbDriver **driver;
  7. };
  8. static void error_handler(void *p)
  9. {
  10. const struct handler_input *input = (const struct handler_input *)p;
  11. if (input->driver && *input->driver)
  12. db_close_database_shutdown_driver(*input->driver);
  13. if (input->Map) {
  14. char *name = G_store(input->Map->name);
  15. if (input->Map->open == VECT_OPEN_CODE)
  16. Vect_close(input->Map);
  17. Vect_delete(name);
  18. G_free(name);
  19. }
  20. }
  21. void set_error_handler(struct Map_info *Map, dbDriver **driver)
  22. {
  23. struct handler_input *input = G_malloc(sizeof(struct handler_input));
  24. input->Map = Map;
  25. input->driver = driver;
  26. G_add_error_handler(error_handler, input);
  27. }