diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-19 02:53:32 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-19 02:53:32 +0000 |
commit | bea0037dbdd979603fb0b5be8b43f5478c1f6fec (patch) | |
tree | 5776ae3af5a3e83d41c7087f70713952b6360988 /src/skaembutils/s6-chmod.c | |
download | s6-portable-utils-bea0037dbdd979603fb0b5be8b43f5478c1f6fec.tar.xz |
initial commit
Diffstat (limited to 'src/skaembutils/s6-chmod.c')
-rw-r--r-- | src/skaembutils/s6-chmod.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/skaembutils/s6-chmod.c b/src/skaembutils/s6-chmod.c new file mode 100644 index 0000000..9cf6f80 --- /dev/null +++ b/src/skaembutils/s6-chmod.c @@ -0,0 +1,34 @@ +/* ISC license. */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <skalibs/uint.h> +#include <skalibs/strerr2.h> + +#define USAGE "s6-chmod mode file" + +int main (int argc, char const *const *argv) +{ + mode_t mode = 0 ; + unsigned int m ; + PROG = "s6-chmod" ; + if (argc < 3) strerr_dieusage(100, USAGE) ; + if (!uint0_oscan(argv[1], &m)) strerr_dieusage(100, USAGE) ; + + if (m & 0001) mode |= S_IXOTH ; + if (m & 0002) mode |= S_IWOTH ; + if (m & 0004) mode |= S_IROTH ; + if (m & 0010) mode |= S_IXGRP ; + if (m & 0020) mode |= S_IWGRP ; + if (m & 0040) mode |= S_IRGRP ; + if (m & 0100) mode |= S_IXUSR ; + if (m & 0200) mode |= S_IWUSR ; + if (m & 0400) mode |= S_IRUSR ; + if (m & 01000) mode |= S_ISVTX ; + if (m & 02000) mode |= S_ISGID ; + if (m & 04000) mode |= S_ISUID ; + + if (chmod(argv[2], mode) == -1) + strerr_diefu2sys(111, "change mode of ", argv[2]) ; + return 0 ; +} |