ladybird/Userland/chmod.cpp
Andreas Kling c30e2c8d44 Implement basic chmod() syscall and /bin/chmod helper.
Only raw octal modes are supported right now.
This patch also changes mode_t from 32-bit to 16-bit to match the on-disk
type used by Ext2FS.

I also ran into EPERM being errno=0 which was confusing, so I inserted an
ESUCCESS in its place.
2019-01-29 04:55:08 +01:00

27 lines
461 B
C++

#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc != 3) {
printf("usage: chmod <octal-mode> <path>\n");
return 1;
}
mode_t mode;
int rc = sscanf(argv[1], "%o", &mode);
if (rc != 1) {
perror("sscanf");
return 1;
}
rc = chmod(argv[2], mode);
if (rc < 0) {
perror("chmod");
return 1;
}
return 0;
}