This is a maintenance fork
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
  2. vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
  3. Copyright 2020 Justine Alexandra Roberts Tunney
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  14. 02110-1301 USA
  15. */
  16. #include "libc/calls/calls.h"
  17. #include "libc/calls/internal.h"
  18. #include "libc/dce.h"
  19. #include "libc/sysv/consts/at.h"
  20. #include "libc/sysv/errfuns.h"
  21. /**
  22. * Changes permissions on file, e.g.:
  23. *
  24. * CHECK_NE(-1, chmod("foo/bar.txt", 0644));
  25. * CHECK_NE(-1, chmod("o/default/program.com", 0755));
  26. * CHECK_NE(-1, chmod("privatefolder/", 0700));
  27. *
  28. * The esoteric bits generally available on System Five are:
  29. *
  30. * CHECK_NE(-1, chmod("/opt/", 01000)); // sticky bit
  31. * CHECK_NE(-1, chmod("/usr/bin/sudo", 04755)); // setuid bit
  32. * CHECK_NE(-1, chmod("/usr/bin/wall", 02755)); // setgid bit
  33. *
  34. * This works on Windows NT if you ignore the error ;-)
  35. *
  36. * @param pathname must exist
  37. * @param mode contains octal flags (base 8)
  38. * @errors ENOENT, ENOTDIR, ENOSYS
  39. * @asyncsignalsafe
  40. * @see fchmod()
  41. * @syscall
  42. */
  43. int chmod(const char *pathname, uint32_t mode) {
  44. if (!pathname) return efault();
  45. return fchmodat$sysv(AT_FDCWD, pathname, mode, 0);
  46. }