ret_codes.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*!
  2. \file lib/db/dbmi_base/ret_codes.c
  3. \brief DBMI Library (base) - return codes (internal use only)
  4. \todo Are we as restrictive here as for vector names?
  5. (C) 1999-2009, 2011 by the GRASS Development Team
  6. This program is free software under the GNU General Public License
  7. (>=v2). Read the file COPYING that comes with GRASS for details.
  8. \author Joel Jones (CERL/UIUC), Radim Blazek
  9. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  10. */
  11. #include <stdlib.h>
  12. #include <grass/dbmi.h>
  13. #include "macros.h"
  14. /*!
  15. \brief Send success code
  16. \return DB_OK
  17. */
  18. int db__send_success()
  19. {
  20. DB_SEND_INT(DB_OK);
  21. return DB_OK;
  22. }
  23. /*!
  24. \brief Send failure code
  25. \return DB_OK
  26. */
  27. int db__send_failure()
  28. {
  29. DB_SEND_INT(DB_FAILED);
  30. DB_SEND_C_STRING(db_get_error_msg());
  31. return DB_OK;
  32. }
  33. /*!
  34. \brief Receive return code
  35. \param[out] ret_code return code
  36. \return DB_OK on success
  37. */
  38. int db__recv_return_code(int *ret_code)
  39. {
  40. dbString err_msg;
  41. /* get the return code first */
  42. DB_RECV_INT(ret_code);
  43. /* if OK, we're done here */
  44. if (*ret_code == DB_OK)
  45. return DB_OK;
  46. /* should be DB_FAILED */
  47. if (*ret_code != DB_FAILED) {
  48. db_protocol_error();
  49. return DB_PROTOCOL_ERR;
  50. }
  51. /* get error message from driver */
  52. db_init_string(&err_msg);
  53. DB_RECV_STRING(&err_msg);
  54. db_error(db_get_string(&err_msg));
  55. db_free_string(&err_msg);
  56. return DB_OK;
  57. }