| 1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- |
| 2 | * |
| 3 | * Copyright 2019 Collabora Ltd. |
| 4 | * SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library 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. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "libglnx-config.h"cxx . . $ `<file>/build/subprojects/libglnx/libglnx-config.h`/ |
| 23 | #include "libglnx-testlib.h"cxx . . $ `<file>/subprojects/libglnx/tests/libglnx-testlib.h`/ |
| 24 | |
| 25 | #include <errno.h> |
| 26 | #include <fcntl.h> |
| 27 | |
| 28 | #include <glib/gstdio.h> |
| 29 | |
| 30 | #include "libglnx.h"cxx . . $ `<file>/subprojects/libglnx/libglnx.h`/ |
| 31 | |
| 32 | struct _GLnxTestAutoTempDircxx . . $ _GLnxTestAutoTempDir# |
| 33 | { |
| 34 | gcharcxx . . $ gchar# *old_cwdcxx . . $ _GLnxTestAutoTempDir#old_cwd.; |
| 35 | int old_cwd_fdcxx . . $ _GLnxTestAutoTempDir#old_cwd_fd.; |
| 36 | GLnxTmpDircxx . . $ GLnxTmpDir# temp_dircxx . . $ _GLnxTestAutoTempDir#temp_dir.; |
| 37 | }; |
| 38 | |
| 39 | _GLnxTestAutoTempDircxx . . $ _GLnxTestAutoTempDir# * |
| 40 | _glnx_test_auto_temp_dir_entercxx . . $ _glnx_test_auto_temp_dir_enter(7a13244e50b9041d). (void) |
| 41 | { |
| 42 | GErrorcxx . . $ GError# *error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 43 | _GLnxTestAutoTempDircxx . . $ _GLnxTestAutoTempDir# *ret = g_new0cxx . . $ `<external>/1123956534522462559/gmem.h:335:9`! (_GLnxTestAutoTempDir, 1); |
| 44 | |
| 45 | glnx_mkdtempcxx . . $ glnx_mkdtemp(a9f251f616dfa564). ("glnx-test-XXXXXX", 0700, &ret->temp_dircxx . . $ _GLnxTestAutoTempDir#temp_dir., &error); |
| 46 | g_assert_no_errorcxx . . $ `<external>/15287032793271088244/gtestutils.h:217:9`! (error); |
| 47 | |
| 48 | /* just for better diagnostics */ |
| 49 | ret->old_cwdcxx . . $ _GLnxTestAutoTempDir#old_cwd. = g_get_current_dircxx . . $ g_get_current_dir(41208ce6ca65dd58). (); |
| 50 | |
| 51 | glnx_opendiratcxx . . $ glnx_opendirat(eb9f38a2463f19dd). (-1, ".", TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, &ret->old_cwd_fdcxx . . $ _GLnxTestAutoTempDir#old_cwd_fd., &error); |
| 52 | g_assert_no_errorcxx . . $ `<external>/15287032793271088244/gtestutils.h:217:9`! (error); |
| 53 | |
| 54 | if (fchdircxx . . $ fchdir(7864480464b09eea). (ret->temp_dircxx . . $ _GLnxTestAutoTempDir#temp_dir..fdcxx . . $ $anonymous_type_a217104d0ce37183_0#fd.) != 0) |
| 55 | g_errorcxx . . $ `<external>/5169755362661750954/gmessages.h:353:9`! ("fchdir(<fd for \"%s\">): %s", ret->temp_dir.path, g_strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 56 | |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | _glnx_test_auto_temp_dir_leavecxx . . $ _glnx_test_auto_temp_dir_leave(caeb283f8b203b48). (_GLnxTestAutoTempDircxx . . $ _GLnxTestAutoTempDir# *dir) |
| 62 | { |
| 63 | GErrorcxx . . $ GError# *error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 64 | |
| 65 | if (fchdircxx . . $ fchdir(7864480464b09eea). (dir->old_cwd_fdcxx . . $ _GLnxTestAutoTempDir#old_cwd_fd.) != 0) |
| 66 | g_errorcxx . . $ `<external>/5169755362661750954/gmessages.h:353:9`! ("fchdir(<fd for \"%s\">): %s", dir->old_cwd, g_strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 67 | |
| 68 | glnx_tmpdir_deletecxx . . $ glnx_tmpdir_delete(44da3ec24a796a35). (&dir->temp_dircxx . . $ _GLnxTestAutoTempDir#temp_dir., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &error); |
| 69 | g_assert_no_errorcxx . . $ `<external>/15287032793271088244/gtestutils.h:217:9`! (error); |
| 70 | |
| 71 | glnx_close_fdcxx . . $ `subprojects/libglnx/glnx-local-alloc.h:58:9`! (&dir->old_cwd_fdcxx . . $ _GLnxTestAutoTempDir#old_cwd_fd.); |
| 72 | |
| 73 | g_freecxx . . $ g_free(5d22bdacc48458e8). (dir->old_cwdcxx . . $ _GLnxTestAutoTempDir#old_cwd.); |
| 74 | g_freecxx . . $ g_free(5d22bdacc48458e8). (dir); |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | _glnx_test_assert_fd_was_closedcxx . . $ _glnx_test_assert_fd_was_closed(d4f767463ce0a6b3). (int fd) |
| 79 | { |
| 80 | /* We can't tell a fd was really closed without behaving as though it |
| 81 | * was still valid */ |
| 82 | if (g_test_undefinedcxx . . $ `<external>/15287032793271088244/gtestutils.h:390:9`! ()) |
| 83 | { |
| 84 | int result; |
| 85 | int errsv; |
| 86 | |
| 87 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 88 | result = fcntlcxx . . $ fcntl(cac4efb70f20a0fb). (fd, F_GETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:166:9`!, 0); |
| 89 | errsv = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 90 | g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:53:9`! (result, <, 0); |
| 91 | g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:53:9`! (errsv, ==, EBADFcxx . . $ `<external>/8987895939074593727/errno-base.h:13:9`!); |
| 92 | } |
| 93 | } |