isdir.c 809 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*!
  2. \file lib/db/dbmi_base/isdir.c
  3. \brief DBMI Library (base) - test for directories
  4. (C) 1999-2009, 2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Joel Jones (CERL/UIUC), Radim Blazek
  8. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  9. */
  10. #include <grass/config.h>
  11. #include <grass/dbmi.h>
  12. #include <unistd.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. /*!
  16. \brief Test if path is a directory
  17. \param path pathname
  18. \return DB_OK on success
  19. \return DB_FAILED on failure
  20. */
  21. int db_isdir(const char *path)
  22. {
  23. struct stat x;
  24. if (stat(path, &x) != 0)
  25. return DB_FAILED;
  26. return (S_ISDIR(x.st_mode) ? DB_OK : DB_FAILED);
  27. }