chiark / gitweb /
fd-util: add new helper call fd_duplicate_data_fd()
authorLennart Poettering <lennart@poettering.net>
Fri, 9 Mar 2018 21:45:08 +0000 (22:45 +0100)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
commitb9e2dff07fe8b82a50b081b6032e547632e338f9
treea0bdb58cb9e53dab9d030210e5c4f38f00e2d00d
parent059f624b552e0cedf6683bd7dad62ed950e9f5b4
fd-util: add new helper call fd_duplicate_data_fd()

This call creates an fd from another fd containing the same data.
Specifically, repeated read() on the returned fd should return the same
data as the original fd. This call is useful when we want to copy data
out of disk images and suchlike, and want to be pass fds with the data
around without having to keep the disk image continously mounted.

The implementation tries to be somewhat smart and tries to prefer
memfds/pipes over files in /tmp or /var/tmp based on the size of the
data, but has appropropriate fallbacks in place.
src/basic/fd-util.c
src/basic/fd-util.h
src/test/test-fd-util.c