summaryrefslogtreecommitdiff
path: root/libgjs-private
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2021-04-06 19:54:11 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2021-04-22 22:58:57 +0200
commita6e8c2855d975668db280671b35e31f8c6c4d721 (patch)
treec3a7cbac188038d91d54ba212b83343e3b0968bd /libgjs-private
parent3ebcc34eddfde2deaae18f6b77fff61892fbee60 (diff)
downloadgjs-a6e8c2855d975668db280671b35e31f8c6c4d721.tar.gz
GjsTestTools: Move open_bytes here from GjsPrivate
This is only needed for testing purposes, so no need to expose it in the exported typelib.
Diffstat (limited to 'libgjs-private')
-rw-r--r--libgjs-private/gjs-util.c92
-rw-r--r--libgjs-private/gjs-util.h4
2 files changed, 0 insertions, 96 deletions
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 <locale.h> /* for setlocale */
#include <stddef.h> /* for size_t */
-#include <gio/gio.h>
#include <glib-object.h>
#include <girepository.h>
#include <glib.h>
#include <glib/gi18n.h> /* for bindtextdomain, bind_textdomain_codeset, textdomain */
-#ifdef G_OS_UNIX
-# include <errno.h>
-# include <fcntl.h> /* for FD_CLOEXEC */
-# include <stdarg.h>
-# include <unistd.h> /* for close, write */
-
-# include <glib-unix.h> /* 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_ */