empty.c 876 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. \file lib/manage/empty.c
  3. \brief Manage Library - Check if element is empty
  4. (C) 2001-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 Original author CERL
  8. */
  9. /* look for at least one file in the element */
  10. #include <sys/types.h>
  11. #include <dirent.h>
  12. #include <grass/gis.h>
  13. /*!
  14. \brief Check if element is empty
  15. \param elem element name
  16. \return 1 empty
  17. \return 0 not empty
  18. */
  19. int M__empty(char *elem)
  20. {
  21. DIR *dirp;
  22. struct dirent *dp;
  23. char dir[1024];
  24. int any;
  25. G_file_name(dir, elem, "", G_mapset());
  26. any = 0;
  27. if ((dirp = opendir(dir)) != NULL) {
  28. while (!any && (dp = readdir(dirp)) != NULL) {
  29. if (dp->d_name[0] != '.')
  30. any = 1;
  31. }
  32. closedir(dirp);
  33. }
  34. return any == 0;
  35. }