c_listdb.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*!
  2. * \file db/dbmi_client/c_listdb.c
  3. *
  4. * \brief DBMI Library (client) - list databases
  5. *
  6. * (C) 1999-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. * \author Joel Jones (CERL/UIUC), Radim Blazek
  13. */
  14. #include <grass/dbmi.h>
  15. #include "macros.h"
  16. /*!
  17. \brief List databases
  18. \param driver db driver
  19. \param path db path
  20. \param npaths number of given paths
  21. \param[out] handles handle infos
  22. \param[out] count number of handle infos
  23. \return DB_OK on success
  24. \return DB_FAILED on failure
  25. */
  26. int db_list_databases(dbDriver * driver, dbString * path, int npaths,
  27. dbHandle ** handles, int *count)
  28. {
  29. int ret_code;
  30. int i;
  31. dbHandle *h;
  32. /* start the procedure call */
  33. db__set_protocol_fds(driver->send, driver->recv);
  34. DB_START_PROCEDURE_CALL(DB_PROC_LIST_DATABASES);
  35. /* arguments */
  36. DB_SEND_STRING_ARRAY(path, npaths);
  37. /* get the return code for the procedure call */
  38. DB_RECV_RETURN_CODE(&ret_code);
  39. if (ret_code != DB_OK)
  40. return ret_code; /* ret_code SHOULD == DB_FAILED */
  41. /* results */
  42. DB_RECV_INT(count);
  43. h = db_alloc_handle_array(*count);
  44. for (i = 0; i < *count; i++) {
  45. DB_RECV_HANDLE(&h[i]);
  46. }
  47. *handles = h;
  48. return DB_OK;
  49. }