Index: lib/libc/sys/fcntl.2 =================================================================== --- lib/libc/sys/fcntl.2 +++ lib/libc/sys/fcntl.2 @@ -207,6 +207,16 @@ member of the passed structure must be initialized with the sizeof of .Vt struct kinfo_file , to allow for the interface versioning and evolution. +.It Dv F_GETPATH +Place a pathname corresponding to +.Fa fd +in the buffer pointed by +.Fa arg . +.Fa arg +buffer size must be at least +.Fa PATH_MAX +bytes and must be a +.Fa char * . .El .Pp The flags for the Index: lib/libc/sys/fcntl.c =================================================================== --- lib/libc/sys/fcntl.c +++ lib/libc/sys/fcntl.c @@ -38,18 +38,35 @@ #include #include +#include #include #include +#include #include "libc_private.h" #pragma weak fcntl int fcntl(int fd, int cmd, ...) { - va_list args; long arg; + va_list args; va_start(args, cmd); + + if (cmd == F_GETPATH) { + struct kinfo_file kif = {.kf_structsize = KINFO_FILE_SIZE}; + char* buf = va_arg(args, char *); + va_end(args); + + int r = (((int (*)(int, int, ...)) + __libc_interposing[INTERPOS_fcntl])(fd, F_KINFO, &kif)); + if (r == -1) + return (-1); + + strcpy(buf, kif.kf_path); + return (r); + } + arg = va_arg(args, long); va_end(args); Index: sys/sys/fcntl.h =================================================================== --- sys/sys/fcntl.h +++ sys/sys/fcntl.h @@ -271,6 +271,7 @@ #define F_GET_SEALS 20 #define F_ISUNIONSTACK 21 /* Kludge for libc, don't use it. */ #define F_KINFO 22 /* Return kinfo_file for this fd */ +#define F_GETPATH 23 /* Return the path for this fd */ /* Seals (F_ADD_SEALS, F_GET_SEALS). */ #define F_SEAL_SEAL 0x0001 /* Prevent adding sealings */