access 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. .TH ACCESS 2
  2. .SH NAME
  3. access \- determine accessibility of file
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .B
  10. int access(char *name, int mode)
  11. .SH DESCRIPTION
  12. .I Access
  13. evaluates the given
  14. file
  15. .I name
  16. for accessibility.
  17. If \fImode\fL&4\fR
  18. is nonzero,
  19. read permission is expected;
  20. if \fImode\fL&2\fR,
  21. write permission;
  22. if \fImode\fL&1\fR,
  23. execute permission.
  24. If \fImode\fL==0\fR,
  25. the file merely need exist.
  26. In any case
  27. all directories leading to the file
  28. must permit searches.
  29. Zero is returned if the desired access is permitted,
  30. \-1 if not.
  31. .PP
  32. Only access bits are checked.
  33. A file may look executable, but
  34. .IR exec (2)
  35. will fail unless it is in proper format.
  36. .PP
  37. The include file
  38. .F <libc.h>
  39. defines
  40. .BR AEXIST =0,
  41. .BR AEXEC =1,
  42. .BR AWRITE =2,
  43. and
  44. .BR AREAD =4.
  45. .PP
  46. .SH SOURCE
  47. .B /sys/src/libc/9sys/access.c
  48. .SH SEE ALSO
  49. .IR stat (2)
  50. .SH DIAGNOSTICS
  51. Sets
  52. .IR errstr .
  53. .SH BUGS
  54. Since file permissions are checked by the server and group information
  55. is not known to the client,
  56. .I access
  57. must open the file to check permissions.
  58. (It calls
  59. .IR stat (2)
  60. to check simple existence.)
  61. Besides giving misleading information about the writability of directories,
  62. this is as expensive as the open that
  63. .I access
  64. is often intended to avoid.