21 #include <grass/gis.h>
26 #include <sys/types.h>
72 if (!S_ISDIR(sb.st_mode)) {
77 if (
G_lstat(dst, &sb) == 0 && S_ISDIR(sb.st_mode)) {
79 const char *p = strrchr(src,
'/');
82 sprintf(path,
"%s/%s", dst, (p ? p + 1 : src));
87 if ((fd = open(src, O_RDONLY)) < 0)
91 open(dst, O_CREAT | O_TRUNC | O_WRONLY,
92 sb.st_mode & 0777)) < 0) {
97 while ((len = read(fd, buf,
sizeof(buf))) > 0) {
98 while (len && (len2 = write(fd2, buf, len)) >= 0)
115 if (!S_ISDIR(sb.st_mode)) {
116 if (
remove(dst) < 0 ||
G_mkdir(dst) < 0)
125 char path[GPATH_MAX], path2[GPATH_MAX];
126 struct dirent *dp =
readdir(dirp);
132 if (dp->d_name[0] ==
'.')
135 sprintf(path,
"%s/%s", src, dp->d_name);
136 sprintf(path2,
"%s/%s", dst, dp->d_name);
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G_mkdir(const char *path)
Creates a new directory.
int G_recursive_copy(const char *src, const char *dst)
int G_lstat(const char *file_name, struct stat *buf)
Get file status.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]