]> git.ipfire.org Git - thirdparty/systemd.git/commit
fileio: introduce take_fdopen{_unlocked}() variant
authorVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 07:49:07 +0000 (00:49 -0700)
committerVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 13:48:00 +0000 (06:48 -0700)
commit3ebbb6cb394f8a328a9bba782e3b1cbeac4d9a7b
tree6dbf669b9ba1637652f35bfeb088286f7237124b
parent3aeea37d88b8a5d6703a34bc310baf925c6066bf
fileio: introduce take_fdopen{_unlocked}() variant

With the addition of _cleanup_close_ there's a repetitious
pattern of assigning -1 to the fd after a successful fdopen
to prevent its close on cleanup now that the FILE * owns the
fd.

This introduces a wrapper that instead takes a pointer to the
fd being opened, and always overwrites the fd with -1 on success.

A future commit will cleanup all the fdopen call sites to use the
wrapper and elide the manual -1 fd assignment.
src/basic/fileio.c
src/basic/fileio.h