set_error_handler.c 706 B

1234567891011121314151617181920212223242526272829303132
  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. if (input->Map->open == VECT_OPEN_CODE)
  15. Vect_close(input->Map);
  16. Vect_delete(input->Map->name);
  17. }
  18. }
  19. void set_error_handler(struct Map_info *Map, dbDriver **driver)
  20. {
  21. struct handler_input *input = G_malloc(sizeof(struct handler_input));
  22. input->Map = Map;
  23. input->driver = driver;
  24. G_add_error_handler(error_handler, input);
  25. }