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)
97 if ((fd2 = open(
dst, O_CREAT | O_TRUNC | O_WRONLY, sb.st_mode & 0777)) <
103 while ((len = read(fd, buf,
sizeof(buf))) > 0) {
104 while (len && (len2 = write(fd2, buf, len)) >= 0)
121 if (!S_ISDIR(sb.st_mode)) {
132 struct dirent *dp = readdir(dirp);
138 if (dp->d_name[0] ==
'.')
141 sprintf(
path,
"%s/%s",
src, dp->d_name);
142 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_lstat(const char *, struct stat *)
Get file status.
int G_mkdir(const char *)
Creates a new directory.