GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
empty.c
Go to the documentation of this file.
1 /*!
2  \file lib/manage/empty.c
3 
4  \brief Manage Library - Check if element is empty
5 
6  (C) 2001-2011 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12 */
13 
14 /* look for at least one file in the element */
15 #include <sys/types.h>
16 #include <dirent.h>
17 
18 #include <grass/gis.h>
19 
20 /*!
21  \brief Check if element is empty
22 
23  \param elem element name
24 
25  \return 1 empty
26  \return 0 not empty
27 */
28 int M__empty(char *elem)
29 {
30  DIR *dirp;
31  struct dirent *dp;
32  char dir[1024];
33  int any;
34 
35  G_file_name(dir, elem, "", G_mapset());
36 
37  any = 0;
38  if ((dirp = opendir(dir)) != NULL) {
39  while (!any && (dp = readdir(dirp)) != NULL) {
40  if (dp->d_name[0] != '.')
41  any = 1;
42  }
43  closedir(dirp);
44  }
45 
46  return any == 0;
47 }
DIR * opendir()
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
Definition: file_name.c:38
#define NULL
Definition: ccmath.h:32
dir_entry * readdir()
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
int M__empty(char *elem)
Check if element is empty.
Definition: empty.c:28