gmain: Add g_steal_fd() to API

This is basically glnx_steal_fd() from libglnx. We already had two
private implementations of it in GLib.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie
2021-03-22 11:48:10 +00:00
committed by Philip Withnall
parent 46c34ea20f
commit 6c5a227bcc
6 changed files with 69 additions and 23 deletions

View File

@@ -6122,3 +6122,23 @@ g_get_worker_context (void)
return glib_worker_context;
}
/**
* g_steal_fd:
* @fd_ptr: (not optional) (inout): A pointer to a file descriptor
*
* Sets @fd_ptr to `-1`, returning the value that was there before.
*
* Conceptually, this transfers the ownership of the file descriptor
* from the referenced variable to the caller of the function (i.e.
* steals the reference). This is very similar to g_steal_pointer(),
* but for file descriptors.
*
* On POSIX platforms, this function is async-signal safe
* (see [`signal(7)`](man:signal(7)) and
* [`signal-safety(7)`](man:signal-safety(7))), making it safe to call from a
* signal handler or a #GSpawnChildSetupFunc.
*
* Returns: the value that @fd_ptr previously had
* Since: 2.70
*/