km_bdb_util.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * $Id$
  3. *
  4. * db_berkeley module, portions of this code were templated using
  5. * the dbtext and postgres modules.
  6. * Copyright (C) 2007 Cisco Systems
  7. *
  8. * This file is part of SIP-router, a free SIP server.
  9. *
  10. * SIP-router is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * SIP-router is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * History:
  25. * --------
  26. * 2007-09-19 genesis (wiquan)
  27. */
  28. /*! \file
  29. * Berkeley DB : Utilities
  30. *
  31. * \ingroup database
  32. */
  33. #include <string.h>
  34. #include <sys/types.h>
  35. #include <dirent.h>
  36. #include "km_bdb_util.h"
  37. /**
  38. *
  39. */
  40. int km_bdb_is_database(str *_s)
  41. {
  42. DIR *dirp = NULL;
  43. char buf[512];
  44. if(!_s || !_s->s || _s->len <= 0 || _s->len > 510)
  45. return 0;
  46. strncpy(buf, _s->s, _s->len);
  47. buf[_s->len] = 0;
  48. dirp = opendir(buf);
  49. if(!dirp)
  50. return 0;
  51. closedir(dirp);
  52. return 1;
  53. }