ret_codes.c 765 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdlib.h>
  2. #include <grass/dbmi.h>
  3. #include "macros.h"
  4. int db__send_success()
  5. {
  6. DB_SEND_INT(DB_OK);
  7. return DB_OK;
  8. }
  9. int db__send_failure()
  10. {
  11. DB_SEND_INT(DB_FAILED);
  12. DB_SEND_C_STRING(db_get_error_msg());
  13. return DB_OK;
  14. }
  15. int db__recv_return_code(int *ret_code)
  16. {
  17. dbString err_msg;
  18. /* get the return code first */
  19. DB_RECV_INT(ret_code);
  20. /* if OK, we're done here */
  21. if (*ret_code == DB_OK)
  22. return DB_OK;
  23. /* should be DB_FAILED */
  24. if (*ret_code != DB_FAILED) {
  25. db_protocol_error();
  26. return DB_PROTOCOL_ERR;
  27. }
  28. /* get error message from driver */
  29. db_init_string(&err_msg);
  30. DB_RECV_STRING(&err_msg);
  31. db_error(db_get_string(&err_msg));
  32. db_free_string(&err_msg);
  33. return DB_OK;
  34. }