25 #include <sys/types.h> 79 if (!S_ISDIR(sb.st_mode)) {
84 if (
G_lstat(dst, &sb) == 0 && S_ISDIR(sb.st_mode)) {
86 const char *p = strrchr(src,
'/');
89 sprintf(path,
"%s/%s", dst, (p ? p + 1 : src));
94 if ((fd = open(src, O_RDONLY)) < 0)
98 open(dst, O_CREAT | O_TRUNC | O_WRONLY,
99 sb.st_mode & 0777)) < 0) {
104 while ((len = read(fd, buf,
sizeof(buf))) > 0) {
105 while (len && (len2 = write(fd2, buf, len)) >= 0)
122 if (!S_ISDIR(sb.st_mode)) {
123 if (
remove(dst) < 0 ||
G_mkdir(dst) < 0)
133 struct dirent *dp =
readdir(dirp);
139 if (dp->d_name[0] ==
'.')
142 sprintf(path,
"%s/%s", src, dp->d_name);
143 sprintf(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 *)
Creates a new directory.
int G_lstat(const char *, struct stat *)
Get file status.