Skip to content
Snippets Groups Projects
Commit 381ca54e authored by Colin Walters's avatar Colin Walters
Browse files

dirfd: Add API to get an absolute path from a dfd/relpath

There are a lot of APIs that still only take absolute paths, such as
librpm (and everything above it).  I plan to use this in rpm-ostree to
convert temporary directories that I'm accessing fd-relative back into
absolutes until such time as fd-relative APIs are plumbed through the
stack more.
parent c231a3b8
Branches
Tags
No related merge requests found
...@@ -204,3 +204,25 @@ glnx_dirfd_iterator_clear (GLnxDirFdIterator *dfd_iter) ...@@ -204,3 +204,25 @@ glnx_dirfd_iterator_clear (GLnxDirFdIterator *dfd_iter)
(void) closedir (real_dfd_iter->d); (void) closedir (real_dfd_iter->d);
real_dfd_iter->initialized = FALSE; real_dfd_iter->initialized = FALSE;
} }
/**
* glnx_fdrel_abspath:
* @dfd: Directory fd
* @path: Path
*
* Turn a fd-relative pair into something that can be used for legacy
* APIs expecting absolute paths.
*
* This is Linux specific, and only valid inside this process (unless
* you set up the child process to have the exact same fd number, but
* don't try that).
*/
char *
glnx_fdrel_abspath (int dfd,
const char *path)
{
dfd = glnx_dirfd_canonicalize (dfd);
if (dfd == AT_FDCWD)
return g_strdup (path);
return g_strdup_printf ("/proc/self/fd/%d/%s", dfd, path);
}
...@@ -74,4 +74,7 @@ gboolean glnx_opendirat (int dfd, ...@@ -74,4 +74,7 @@ gboolean glnx_opendirat (int dfd,
int *out_fd, int *out_fd,
GError **error); GError **error);
char *glnx_fdrel_abspath (int dfd,
const char *path);
G_END_DECLS G_END_DECLS
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment