Skip to content
Snippets Groups Projects
resolve-in-sysroot.c 10.79 KiB
/*
 * Copyright © 2020 Collabora Ltd.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#include "resolve-in-sysroot.h"

#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>

#include "libglnx/libglnx.h"

#include "glib-backports.h"

/* Enabling debug logging for this is rather too verbose, so only
 * enable it when actively debugging this module */
#if 0
#define trace(...) g_debug (__VA_ARGS__)
#else
#define trace(...) do { } while (0)
#endif

/*
 * clear_fd:
 * @p: A pointer into the data array underlying a #GArray.
 *
 * Close the fd pointed to by @p, and set `*(int *) p` to -1.
 *
 * This wraps glnx_close_fd() with the signature required by
 * g_array_set_clear_func().
 */
static void
clear_fd (void *p)
{
  glnx_close_fd (p);
}

/*
 * Steal `*fdp` and append it to @fds.
 *
 * We can't just use g_array_append_val (fds, glnx_steal_fd (&fd))
 * because g_array_append_val is a macro that takes a pointer to its
 * argument.
 */
static inline void
fd_array_take (GArray *fds,
               int *fdp)
{
  int fd = glnx_steal_fd (fdp);

  g_array_append_val (fds, fd);
}

/*
 * pv_resolve_in_sysroot: