1 /*
2 * Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright 2023 Collabora Ltd.
4 *
5 * SPDX-License-Identifier: LicenseRef-old-glib-tests
6 *
7 * This work is provided "as is"; redistribution and modification
8 * in whole or in part, in any medium, physical or electronic is
9 * permitted without restriction.
10 *
11 * This work is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * In no event shall the authors or contributors be liable for any
16 * direct, indirect, incidental, special, exemplary, or consequential
17 * damages (including, but not limited to, procurement of substitute
18 * goods or services; loss of use, data, or profits; or business
19 * interruption) however caused and on any theory of liability, whether
20 * in contract, strict liability, or tort (including negligence or
21 * otherwise) arising in any way out of the use of this software, even
22 * if advised of the possibility of such damage.
23 */
24
25 #include "config.h"
26
27 #include <errno.h>
28
29 #include "glib-private.h"
30 #include "gstdio.h"
31
32 static inline void
33 assert_fd_was_closed (int fd)
34 {
35 /* We can't tell a fd was really closed without behaving as though it
36 * was still valid */
37 if (g_test_undefined ())
38 {
39 int result, errsv;
40 GWin32InvalidParameterHandler handler;
41
42 GLIB_PRIVATE_CALL (g_win32_push_empty_invalid_parameter_handler) (&handler);
43 result = g_fsync (fd);
44 errsv = errno;
45 GLIB_PRIVATE_CALL (g_win32_pop_invalid_parameter_handler) (&handler);
46
47 g_assert_cmpint (result, !=, 0);
48 g_assert_cmpint (errsv, ==, EBADF);
49 }
50 }