From a6e8c2855d975668db280671b35e31f8c6c4d721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 6 Apr 2021 19:54:11 +0200 Subject: GjsTestTools: Move open_bytes here from GjsPrivate This is only needed for testing purposes, so no need to expose it in the exported typelib. --- libgjs-private/gjs-util.c | 92 ----------------------------------------------- libgjs-private/gjs-util.h | 4 --- 2 files changed, 96 deletions(-) (limited to 'libgjs-private') diff --git a/libgjs-private/gjs-util.c b/libgjs-private/gjs-util.c index 4fd268cd..9dbe5f6f 100644 --- a/libgjs-private/gjs-util.c +++ b/libgjs-private/gjs-util.c @@ -9,21 +9,11 @@ #include /* for setlocale */ #include /* for size_t */ -#include #include #include #include #include /* for bindtextdomain, bind_textdomain_codeset, textdomain */ -#ifdef G_OS_UNIX -# include -# include /* for FD_CLOEXEC */ -# include -# include /* for close, write */ - -# include /* for g_unix_open_pipe */ -#endif - #include "libgjs-private/gjs-util.h" char * @@ -108,88 +98,6 @@ gjs_param_spec_get_owner_type(GParamSpec *pspec) return pspec->owner_type; } -#ifdef G_OS_UNIX - -// Adapted from glnx_throw_errno_prefix() -G_GNUC_PRINTF(2, 3) -static gboolean throw_errno_prefix(GError** error, const char* fmt, ...) { - int errsv = errno; - char* old_msg; - GString* buf; - - va_list args; - - if (!error) - return FALSE; - - va_start(args, fmt); - - g_set_error_literal(error, G_IO_ERROR, g_io_error_from_errno(errsv), - g_strerror(errsv)); - - old_msg = g_steal_pointer(&(*error)->message); - buf = g_string_new(""); - g_string_append_vprintf(buf, fmt, args); - g_string_append(buf, ": "); - g_string_append(buf, old_msg); - g_free(old_msg); - (*error)->message = g_string_free(g_steal_pointer(&buf), FALSE); - - va_end(args); - - errno = errsv; - return FALSE; -} - -#endif /* G_OS_UNIX */ - -/** - * gjs_open_bytes: - * @bytes: bytes to send to the pipe - * @error: Return location for a #GError, or %NULL - * - * Creates a pipe and sends @bytes to it, such that it is suitable for passing - * to g_subprocess_launcher_take_fd(). - * - * Returns: file descriptor, or -1 on error - */ -int gjs_open_bytes(GBytes* bytes, GError** error) { - int pipefd[2], result; - size_t count; - const void* buf; - ssize_t bytes_written; - - g_return_val_if_fail(bytes, -1); - g_return_val_if_fail(error == NULL || *error == NULL, -1); - -#ifdef G_OS_UNIX - if (!g_unix_open_pipe(pipefd, FD_CLOEXEC, error)) - return -1; - - buf = g_bytes_get_data(bytes, &count); - - bytes_written = write(pipefd[1], buf, count); - if (bytes_written < 0) { - throw_errno_prefix(error, "write"); - return -1; - } - - if ((size_t)bytes_written != count) - g_warning("%s: %zu bytes sent, only %zd bytes written", __func__, count, - bytes_written); - - result = close(pipefd[1]); - if (result == -1) { - throw_errno_prefix(error, "close"); - return -1; - } - - return pipefd[0]; -#else - g_error("%s is currently supported on UNIX only", __func__); -#endif -} - static GParamSpec* gjs_gtk_container_class_find_child_property( GIObjectInfo* container_info, GObject* container, const char* property) { GIBaseInfo* class_info = NULL; diff --git a/libgjs-private/gjs-util.h b/libgjs-private/gjs-util.h index d4f8bbf6..c24f2359 100644 --- a/libgjs-private/gjs-util.h +++ b/libgjs-private/gjs-util.h @@ -57,10 +57,6 @@ void gjs_gtk_container_child_set_property(GObject* container, GObject* child, const char* property, const GValue* value); -/* For tests */ -GJS_EXPORT -int gjs_open_bytes(GBytes* bytes, GError** error); - G_END_DECLS #endif /* LIBGJS_PRIVATE_GJS_UTIL_H_ */ -- cgit v1.2.1