-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
empty.c
47 lines (35 loc) · 881 Bytes
/
empty.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*!
\file lib/manage/empty.c
\brief Manage Library - Check if element is empty
(C) 2001-2011 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Original author CERL
*/
/* look for at least one file in the element */
#include <sys/types.h>
#include <dirent.h>
#include <grass/gis.h>
/*!
\brief Check if element is empty
\param elem element name
\return 1 empty
\return 0 not empty
*/
int M__empty(char *elem)
{
DIR *dirp;
struct dirent *dp;
char dir[GPATH_MAX];
int any;
G_file_name(dir, elem, "", G_mapset());
any = 0;
if ((dirp = opendir(dir)) != NULL) {
while (!any && (dp = readdir(dirp)) != NULL) {
if (dp->d_name[0] != '.')
any = 1;
}
closedir(dirp);
}
return any == 0;
}