d_listdb.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. * \file db/dbmi_driver/d_listdb.c
  3. *
  4. * \brief DBMI Library (driver) - 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 <stdlib.h>
  15. #include <grass/dbmi.h>
  16. #include "macros.h"
  17. #include "dbstubs.h"
  18. /*!
  19. \brief List databases
  20. \return DB_OK on success
  21. \return DB_FAILED on failure
  22. */
  23. int db_d_list_databases(void)
  24. {
  25. dbHandle *handles;
  26. dbString *path;
  27. int npaths;
  28. int i, count;
  29. int stat;
  30. /* arg(s) */
  31. DB_RECV_STRING_ARRAY(&path, &npaths);
  32. /* call the procedure */
  33. stat = db_driver_list_databases(path, npaths, &handles, &count);
  34. db_free_string_array(path, npaths);
  35. /* send the return code */
  36. if (stat != DB_OK) {
  37. DB_SEND_FAILURE();
  38. return DB_OK;
  39. }
  40. DB_SEND_SUCCESS();
  41. /* send results */
  42. DB_SEND_INT(count);
  43. for (i = 0; i < count; i++) {
  44. DB_SEND_HANDLE(&handles[i]);
  45. }
  46. db_free_handle_array(handles, count);
  47. return DB_OK;
  48. }