gstdio: Add support for the e flag (O_CLOEXEC) to g_fopen()

This adds cross-platform support for it: on glibc, musl and BSD’s libc,
the flag is natively supported. On Windows, convert it to the `N` flag,
which similarly indicates that an open file shouldn’t be inherited by
child processes.

This allows us to unconditionally pass `e` to `g_fopen()` so `O_CLOEXEC`
can easily be set on its FDs.

Also do the same for `g_freopen()`, since it shares the same underlying
mode handling code.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-03-20 12:27:21 +00:00
parent c108dc09b9
commit f9a7ac11f5
18 changed files with 57 additions and 33 deletions

View File

@@ -1131,7 +1131,7 @@ main (int argc, char **argv)
{
FILE *file;
file = fopen (target, "w");
file = g_fopen (target, "we");
if (file == NULL)
{
g_printerr ("can't write to file %s", target);
@@ -1180,7 +1180,7 @@ main (int argc, char **argv)
}
g_unlink (binary_target);
file = fopen (target, "w");
file = g_fopen (target, "we");
if (file == NULL)
{
g_printerr ("can't write to file %s", target);