17 #include <grass/config.h>
22 #include <sys/types.h>
25 #include <grass/gis.h>
27 static int recursive_remove(
const char *path);
28 static int G__remove(
int misc,
const char *dir,
const char *element,
49 return G__remove(0,
NULL, element, name);
69 return G__remove(1, dir, element, name);
72 static int G__remove(
int misc,
const char *dir,
const char *element,
77 char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
82 if (strcmp(mapset, xmapset) != 0)
96 if (access(path, 0) != 0)
99 if (recursive_remove(path) == 0)
106 static int recursive_remove(
const char *path)
111 char path2[GPATH_MAX];
115 if (!S_ISDIR(sb.st_mode))
116 return remove(path) == 0 ? 0 : 1;
121 if (dp->d_name[0] ==
'.')
123 if (strlen(path) + strlen(dp->d_name) + 2 >
sizeof(path2))
125 sprintf(path2,
"%s/%s", path, dp->d_name);
126 recursive_remove(path2);
130 return rmdir(path) == 0 ? 0 : 1;