fd2path 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. .TH FD2PATH 2
  2. .SH NAME
  3. fd2path \- return file name associated with file descriptor
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .B
  10. int fd2path(int fd, char *buf, int nbuf)
  11. .SH DESCRIPTION
  12. As described in
  13. .IR intro (2),
  14. the kernel stores a rooted path name with every open file or directory;
  15. typically, it is the name used in the original access of the file.
  16. .I Fd2path
  17. returns the path name associated with open file descriptor
  18. .IR fd .
  19. Up to
  20. .I nbuf
  21. bytes of the name are stored in
  22. .IR buf ;
  23. if the name is too long, it will be silently truncated at a UTF-8
  24. character boundary.
  25. The name is always null-terminated.
  26. The return value of
  27. .I fd2path
  28. will be zero unless an error occurs.
  29. .PP
  30. Changes to the underlying name space do not update the path name
  31. stored with the file descriptor.
  32. Therefore,
  33. the path returned by
  34. .I fd2path
  35. may no longer refer to the same file (or indeed any file)
  36. after some component directory or file in the path has been removed, renamed
  37. or rebound.
  38. .PP
  39. As an example,
  40. .IR getwd (2)
  41. is implemented by opening
  42. .B .
  43. and executing
  44. .I fd2path
  45. on the resulting file descriptor.
  46. .SH SOURCE
  47. .B /sys/src/libc/9syscall
  48. .SH SEE ALSO
  49. .IR bind (1),
  50. .IR ns (1),
  51. .IR bind (2),
  52. .IR intro (2),
  53. .IR getwd (2),
  54. .IR proc (3)
  55. .SH DIAGNOSTICS
  56. Sets
  57. .IR errstr .