mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
Kernel+Userland: Implement fchmod() syscall and use it to improve /bin/cp.
/bin/cp will now copy the permission bits from source to destination. :^)
This commit is contained in:
parent
b5e5f26a82
commit
1b16a29044
10 changed files with 54 additions and 14 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -9,6 +10,7 @@ int main(int argc, char** argv)
|
|||
printf("usage: cp <source> <destination>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int src_fd = open(argv[1], O_RDONLY);
|
||||
if (src_fd < 0) {
|
||||
perror("open src");
|
||||
|
@ -20,6 +22,13 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
struct stat src_stat;
|
||||
int rc = fstat(src_fd, &src_stat);
|
||||
if (rc < 0) {
|
||||
perror("stat src");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
char buffer[BUFSIZ];
|
||||
ssize_t nread = read(src_fd, buffer, sizeof(buffer));
|
||||
|
@ -42,6 +51,13 @@ int main(int argc, char** argv)
|
|||
bufptr += nwritten;
|
||||
}
|
||||
}
|
||||
|
||||
rc = fchmod(dst_fd, src_stat.st_mode);
|
||||
if (rc < 0) {
|
||||
perror("fchmod dst");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close(src_fd);
|
||||
close(dst_fd);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue