mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 15:33:39 +02:00
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:
@@ -792,7 +792,7 @@ test_internal_enhanced_stdio (void)
|
||||
|
||||
g_remove (ps);
|
||||
|
||||
f = g_fopen (ps, "wb");
|
||||
f = g_fopen (ps, "wbe");
|
||||
g_assert_nonnull (f);
|
||||
|
||||
h = (HANDLE) _get_osfhandle (fileno (f));
|
||||
@@ -875,7 +875,7 @@ test_internal_enhanced_stdio (void)
|
||||
|
||||
g_assert_true (SystemTimeToFileTime (&st, &ft));
|
||||
|
||||
f = g_fopen (p0, "w");
|
||||
f = g_fopen (p0, "we");
|
||||
g_assert_nonnull (f);
|
||||
|
||||
h = (HANDLE) _get_osfhandle (fileno (f));
|
||||
@@ -888,7 +888,7 @@ test_internal_enhanced_stdio (void)
|
||||
|
||||
fclose (f);
|
||||
|
||||
f = g_fopen (p1, "w");
|
||||
f = g_fopen (p1, "we");
|
||||
g_assert_nonnull (f);
|
||||
|
||||
fclose (f);
|
||||
|
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include <glib/glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gio/gio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@@ -305,7 +306,7 @@ test_create_structure (gconstpointer test_data)
|
||||
basename = g_path_get_basename (item.filename);
|
||||
path = g_build_filename (test_data, dir, ".hidden", NULL);
|
||||
|
||||
f = fopen (path, "a");
|
||||
f = g_fopen (path, "ae");
|
||||
fprintf (f, "%s\n", basename);
|
||||
fclose (f);
|
||||
|
||||
|
Reference in New Issue
Block a user