gstdio: Document async-signal-safety of g_clear_fd and g_autofd

g_clear_fd wraps g_close and is async-signal-safe under essentially the
same circumstances. If fd_ptr already pointed to a negative number, then
g_clear_fd doesn't call g_close, and is still async-signal-safe.

g_autofd passes a NULL error pointer to g_clear_fd, so it is
async-signal-safe, as long as no programming error occurs.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-10-28 14:57:19 +01:00
parent e231132fc3
commit 81130a6e3f

View File

@ -1849,6 +1849,9 @@ g_close (gint fd,
* stored in both %errno and @error. If this function succeeds,
* %errno is undefined.
*
* This function is async-signal-safe if @error is %NULL and @fd_ptr
* points to either a negative number or a valid file descriptor.
*
* It is a programming error for @fd_ptr to point to a non-negative
* number that is not a valid file descriptor.
*
@ -1902,6 +1905,9 @@ g_close (gint fd,
* only supported on GCC and clang, and the variable must be initialized
* (to either a valid file descriptor or a negative number).
*
* Using this macro is async-signal-safe if the constraints described above
* are met, so it can be used in a signal handler or after `fork()`.
*
* Any error from closing the file descriptor when it goes out of scope
* is ignored. Use g_clear_fd() if error-checking is required.
*