14 #include <grass/config.h> 19 #include <sys/types.h> 22 #include <grass/gis.h> 24 static int recursive_remove(
const char *
path);
25 static int G__remove(
int misc,
const char *dir,
const char *
element,
47 return G__remove(0,
NULL, element, name);
68 return G__remove(1, dir, element, name);
71 static int G__remove(
int misc,
const char *dir,
const char *
element,
76 char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
81 if (strcmp(mapset, xmapset) != 0)
95 if (access(path, 0) != 0)
98 if (recursive_remove(path) == 0)
105 static int recursive_remove(
const char *
path)
110 char path2[GPATH_MAX];
114 if (!S_ISDIR(sb.st_mode))
115 return remove(path) == 0 ? 0 : 1;
117 if ((dirp = opendir(path)) ==
NULL)
119 while ((dp = readdir(dirp)) !=
NULL) {
120 if (dp->d_name[0] ==
'.')
122 if (strlen(path) + strlen(dp->d_name) + 2 >
sizeof(path2))
124 sprintf(path2,
"%s/%s", path, dp->d_name);
125 recursive_remove(path2);
129 return rmdir(path) == 0 ? 0 : 1;
const char * G_mapset(void)
Get current mapset name.
int G_lstat(const char *file_name, struct stat *buf)
Get file status.
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
int G_remove(const char *element, const char *name)
Remove a database file.
int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)
int G_remove_misc(const char *dir, const char *element, const char *name)
Remove a database misc file.
char * G_file_name_misc(char *path, const char *dir, const char *element, const char *name, const char *mapset)
int G_legal_filename(const char *s)
Check for legal database file name.