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.

44 lines
2.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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. * Checks if effective user can access path in particular ways.
  23. *
  24. * @param path is a filename or directory
  25. * @param mode can be R_OK, W_OK, X_OK, F_OK
  26. * @return 0 if ok, or -1 and sets errno
  27. * @asyncsignalsafe
  28. * @syscall
  29. */
  30. int access(const char *path, int mode) {
  31. char16_t path16[PATH_MAX];
  32. if (!path) return efault();
  33. if (!IsWindows()) {
  34. return faccessat$sysv(AT_FDCWD, path, mode, 0);
  35. } else {
  36. if (__mkntpath(path, path16) == -1) return -1;
  37. return ntaccesscheck(path16, mode);
  38. }
  39. }