ls and cp
This commit is contained in:
parent
19f270c4c1
commit
f2216e7d90
@ -21,13 +21,13 @@ char *make_path(const char *src, const char *dst) {
|
||||
return full_path;
|
||||
}
|
||||
|
||||
int write_buffer(int ifd, int ofd, const char *dst) {
|
||||
int write_buffer(int mode, int ifd, int ofd, const char *dst) {
|
||||
off_t len = lseek(ifd, 0, SEEK_END);
|
||||
if (len < 0)
|
||||
return 1;
|
||||
|
||||
else if (len == 0) {
|
||||
int fd = open(dst, O_CREAT | O_RDONLY, 0666);
|
||||
int fd = open(dst, O_CREAT | O_RDONLY, mode);
|
||||
if (fd < 0)
|
||||
return 1;
|
||||
|
||||
@ -55,18 +55,18 @@ int write_buffer(int ifd, int ofd, const char *dst) {
|
||||
|
||||
}
|
||||
|
||||
int copy(const char *src, const char *dst) {
|
||||
int copy(int mode, const char *src, const char *dst) {
|
||||
int ifd = open(src, O_RDONLY);
|
||||
if (ifd < 0)
|
||||
return 1;
|
||||
|
||||
int ofd = open(dst, O_CREAT | O_TRUNC | O_RDWR, 0644);
|
||||
int ofd = open(dst, O_CREAT | O_TRUNC | O_RDWR, mode);
|
||||
if (ofd < 0) {
|
||||
close(ifd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (write_buffer(ifd, ofd, dst))
|
||||
if (write_buffer(mode, ifd, ofd, dst))
|
||||
fprintf(stderr, "cp: (%s %s) %s\n", src, dst, strerror(errno));
|
||||
|
||||
close(ifd);
|
||||
@ -89,7 +89,7 @@ int cptree(const char *src, const char *dst) {
|
||||
return 1;
|
||||
|
||||
if (S_ISDIR(stat_path.st_mode) == 0) {
|
||||
if (copy(src, dst)) {
|
||||
if (copy(stat_path.st_mode, src, dst)) {
|
||||
fprintf(stderr, "cp: %s: copy() failed (%s)\n", src, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user