20 #include <grass/gis.h>
25 #include <sys/types.h>
78 if (!S_ISDIR(sb.st_mode)) {
83 if (
G_lstat(dst, &sb) == 0 && S_ISDIR(sb.st_mode)) {
85 const char *p = strrchr(src,
'/');
88 snprintf(
path,
sizeof(
path),
"%s/%s", dst, (p ? p + 1 : src));
93 if ((fd = open(src, O_RDONLY)) < 0)
96 if ((fd2 = open(dst, O_CREAT | O_TRUNC | O_WRONLY, sb.st_mode & 0777)) <
102 while ((len = read(fd, buf,
sizeof(buf))) > 0) {
103 while ((len > 0) && (len2 = write(fd2, buf, (
size_t)len)) >= 0)
120 if (!S_ISDIR(sb.st_mode)) {
121 if (remove(dst) < 0 ||
G_mkdir(dst) < 0)
130 char path[GPATH_MAX], path2[GPATH_MAX];
131 struct dirent *dp = readdir(dirp);
137 if (dp->d_name[0] ==
'.')
140 snprintf(
path,
sizeof(
path),
"%s/%s", src, dp->d_name);
141 snprintf(path2,
sizeof(path2),
"%s/%s", dst, dp->d_name);
int G_recursive_copy(const char *src, const char *dst)
Copy recursively source directory to destination directory.
int G_mkdir(const char *path)
Creates a new directory.
int G_lstat(const char *file_name, struct stat *buf)
Get file status.