shithub: riscv

ref: e2124b109ecb0f5634f036e392d827b6ddebec54
dir: /sys/man/2/fd2path/

View raw version
.TH FD2PATH 2
.SH NAME
fd2path \- return file name associated with file descriptor
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.PP
.B
int fd2path(int fd, char *buf, int nbuf)
.SH DESCRIPTION
As described in
.IR intro (2),
the kernel stores a rooted path name with every open file or directory;
typically, it is the name used in the original access of the file.
.I Fd2path
returns the path name associated with open file descriptor
.IR fd .
Up to
.I nbuf
bytes of the name are stored in
.IR buf ;
if the name is too long, it will be silently truncated at a UTF-8
character boundary.
The name is always null-terminated.
The return value of
.I fd2path
will be zero unless an error occurs.
.PP
Changes to the underlying name space do not update the path name
stored with the file descriptor.
Therefore,
the path returned by
.I fd2path
may no longer refer to the same file (or indeed any file)
after some component directory or file in the path has been removed, renamed
or rebound.
.PP
As an example,
.IR getwd (2)
is implemented by opening
.B .
and executing
.I fd2path
on the resulting file descriptor.
.SH SOURCE
.B /sys/src/libc/9syscall
.SH SEE ALSO
.IR bind (1),
.IR ns (1),
.IR bind (2),
.IR intro (2),
.IR getwd (2),
.IR proc (3)
.SH DIAGNOSTICS
Sets
.IR errstr .