/* fd-stream.c generated by valac 0.56.18, the Vala compiler
 * generated from fd-stream.vala, do not modify */

/* FdStream: turn file descriptors into InputStreams and OutputStreams.*/
/**/
/* © 2025 Reuben Thomas <rrt@sc3d.org>*/
/**/
/* This program is free software; you can redistribute it and/or modify*/
/* it under the terms of the GNU General Public License as published by*/
/* the Free Software Foundation; either version 3, or (at your option)*/
/* any later version.*/
/**/
/* This program 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 General Public License for more details.*/
/**/
/* You should have received a copy of the GNU General Public License*/
/* along with this program; if not, see <https://www.gnu.org/licenses/>.*/

#include <gio/gio.h>
#include <glib-object.h>
#include <glib.h>
#include <unistd.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_FD_INPUT_STREAM (fd_input_stream_get_type ())
#define FD_INPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FD_INPUT_STREAM, FdInputStream))
#define FD_INPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FD_INPUT_STREAM, FdInputStreamClass))
#define IS_FD_INPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FD_INPUT_STREAM))
#define IS_FD_INPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FD_INPUT_STREAM))
#define FD_INPUT_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FD_INPUT_STREAM, FdInputStreamClass))

typedef struct _FdInputStream FdInputStream;
typedef struct _FdInputStreamClass FdInputStreamClass;
typedef struct _FdInputStreamPrivate FdInputStreamPrivate;
enum  {
	FD_INPUT_STREAM_0_PROPERTY,
	FD_INPUT_STREAM_NUM_PROPERTIES
};
static GParamSpec* fd_input_stream_properties[FD_INPUT_STREAM_NUM_PROPERTIES];

#define TYPE_FD_OUTPUT_STREAM (fd_output_stream_get_type ())
#define FD_OUTPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FD_OUTPUT_STREAM, FdOutputStream))
#define FD_OUTPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FD_OUTPUT_STREAM, FdOutputStreamClass))
#define IS_FD_OUTPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FD_OUTPUT_STREAM))
#define IS_FD_OUTPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FD_OUTPUT_STREAM))
#define FD_OUTPUT_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FD_OUTPUT_STREAM, FdOutputStreamClass))

typedef struct _FdOutputStream FdOutputStream;
typedef struct _FdOutputStreamClass FdOutputStreamClass;
typedef struct _FdOutputStreamPrivate FdOutputStreamPrivate;
enum  {
	FD_OUTPUT_STREAM_0_PROPERTY,
	FD_OUTPUT_STREAM_NUM_PROPERTIES
};
static GParamSpec* fd_output_stream_properties[FD_OUTPUT_STREAM_NUM_PROPERTIES];

struct _FdInputStream {
	GInputStream parent_instance;
	FdInputStreamPrivate * priv;
};

struct _FdInputStreamClass {
	GInputStreamClass parent_class;
};

struct _FdInputStreamPrivate {
	gint fd;
};

struct _FdOutputStream {
	GOutputStream parent_instance;
	FdOutputStreamPrivate * priv;
};

struct _FdOutputStreamClass {
	GOutputStreamClass parent_class;
};

struct _FdOutputStreamPrivate {
	gint fd;
};

static gint FdInputStream_private_offset;
static gpointer fd_input_stream_parent_class = NULL;
static gint FdOutputStream_private_offset;
static gpointer fd_output_stream_parent_class = NULL;

VALA_EXTERN GType fd_input_stream_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FdInputStream, g_object_unref)
VALA_EXTERN FdInputStream* fd_input_stream_new (gint fd);
VALA_EXTERN FdInputStream* fd_input_stream_construct (GType object_type,
                                          gint fd);
static gboolean fd_input_stream_real_close (GInputStream* base,
                                     GCancellable* cancellable,
                                     GError** error);
static gssize fd_input_stream_real_read (GInputStream* base,
                                  guint8* buffer,
                                  gsize buffer_length1,
                                  GCancellable* cancellable,
                                  GError** error);
static void fd_input_stream_finalize (GObject * obj);
static GType fd_input_stream_get_type_once (void);
VALA_EXTERN GType fd_output_stream_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FdOutputStream, g_object_unref)
VALA_EXTERN FdOutputStream* fd_output_stream_new (gint fd);
VALA_EXTERN FdOutputStream* fd_output_stream_construct (GType object_type,
                                            gint fd);
static gboolean fd_output_stream_real_close (GOutputStream* base,
                                      GCancellable* cancellable,
                                      GError** error);
static gssize fd_output_stream_real_write (GOutputStream* base,
                                    guint8* buffer,
                                    gsize buffer_length1,
                                    GCancellable* cancellable,
                                    GError** error);
static void fd_output_stream_finalize (GObject * obj);
static GType fd_output_stream_get_type_once (void);

static inline gpointer
fd_input_stream_get_instance_private (FdInputStream* self)
{
	return G_STRUCT_MEMBER_P (self, FdInputStream_private_offset);
}

FdInputStream*
fd_input_stream_construct (GType object_type,
                           gint fd)
{
	FdInputStream * self = NULL;
#line 24 "fd-stream.vala"
	self = (FdInputStream*) g_object_new (object_type, NULL);
#line 25 "fd-stream.vala"
	self->priv->fd = fd;
#line 24 "fd-stream.vala"
	return self;
#line 156 "fd-stream.c"
}

FdInputStream*
fd_input_stream_new (gint fd)
{
#line 24 "fd-stream.vala"
	return fd_input_stream_construct (TYPE_FD_INPUT_STREAM, fd);
#line 164 "fd-stream.c"
}

static gboolean
fd_input_stream_real_close (GInputStream* base,
                            GCancellable* cancellable,
                            GError** error)
{
	FdInputStream * self;
	gboolean result;
#line 28 "fd-stream.vala"
	self = (FdInputStream*) base;
#line 29 "fd-stream.vala"
	result = close (self->priv->fd) == 0;
#line 29 "fd-stream.vala"
	return result;
#line 180 "fd-stream.c"
}

static gssize
fd_input_stream_real_read (GInputStream* base,
                           guint8* buffer,
                           gsize buffer_length1,
                           GCancellable* cancellable,
                           GError** error)
{
	FdInputStream * self;
	gssize result;
#line 32 "fd-stream.vala"
	self = (FdInputStream*) base;
#line 33 "fd-stream.vala"
	result = read (self->priv->fd, buffer, (gsize) buffer_length1);
#line 33 "fd-stream.vala"
	return result;
#line 198 "fd-stream.c"
}

static void
fd_input_stream_class_init (FdInputStreamClass * klass,
                            gpointer klass_data)
{
#line 21 "fd-stream.vala"
	fd_input_stream_parent_class = g_type_class_peek_parent (klass);
#line 21 "fd-stream.vala"
	g_type_class_adjust_private_offset (klass, &FdInputStream_private_offset);
#line 21 "fd-stream.vala"
	((GInputStreamClass *) klass)->close_fn = (gboolean (*) (GInputStream*, GCancellable*, GError**)) fd_input_stream_real_close;
#line 21 "fd-stream.vala"
	((GInputStreamClass *) klass)->read_fn = (gssize (*) (GInputStream*, guint8*, gsize, GCancellable*, GError**)) fd_input_stream_real_read;
#line 21 "fd-stream.vala"
	G_OBJECT_CLASS (klass)->finalize = fd_input_stream_finalize;
#line 215 "fd-stream.c"
}

static void
fd_input_stream_instance_init (FdInputStream * self,
                               gpointer klass)
{
#line 21 "fd-stream.vala"
	self->priv = fd_input_stream_get_instance_private (self);
#line 224 "fd-stream.c"
}

static void
fd_input_stream_finalize (GObject * obj)
{
	FdInputStream * self;
#line 21 "fd-stream.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FD_INPUT_STREAM, FdInputStream);
#line 21 "fd-stream.vala"
	G_OBJECT_CLASS (fd_input_stream_parent_class)->finalize (obj);
#line 235 "fd-stream.c"
}

static GType
fd_input_stream_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FdInputStreamClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fd_input_stream_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FdInputStream), 0, (GInstanceInitFunc) fd_input_stream_instance_init, NULL };
	GType fd_input_stream_type_id;
	fd_input_stream_type_id = g_type_register_static (g_input_stream_get_type (), "FdInputStream", &g_define_type_info, 0);
	FdInputStream_private_offset = g_type_add_instance_private (fd_input_stream_type_id, sizeof (FdInputStreamPrivate));
	return fd_input_stream_type_id;
}

GType
fd_input_stream_get_type (void)
{
	static volatile gsize fd_input_stream_type_id__once = 0;
	if (g_once_init_enter (&fd_input_stream_type_id__once)) {
		GType fd_input_stream_type_id;
		fd_input_stream_type_id = fd_input_stream_get_type_once ();
		g_once_init_leave (&fd_input_stream_type_id__once, fd_input_stream_type_id);
	}
	return fd_input_stream_type_id__once;
}

static inline gpointer
fd_output_stream_get_instance_private (FdOutputStream* self)
{
	return G_STRUCT_MEMBER_P (self, FdOutputStream_private_offset);
}

FdOutputStream*
fd_output_stream_construct (GType object_type,
                            gint fd)
{
	FdOutputStream * self = NULL;
#line 40 "fd-stream.vala"
	self = (FdOutputStream*) g_object_new (object_type, NULL);
#line 41 "fd-stream.vala"
	self->priv->fd = fd;
#line 40 "fd-stream.vala"
	return self;
#line 277 "fd-stream.c"
}

FdOutputStream*
fd_output_stream_new (gint fd)
{
#line 40 "fd-stream.vala"
	return fd_output_stream_construct (TYPE_FD_OUTPUT_STREAM, fd);
#line 285 "fd-stream.c"
}

static gboolean
fd_output_stream_real_close (GOutputStream* base,
                             GCancellable* cancellable,
                             GError** error)
{
	FdOutputStream * self;
	gboolean result;
#line 44 "fd-stream.vala"
	self = (FdOutputStream*) base;
#line 45 "fd-stream.vala"
	result = close (self->priv->fd) == 0;
#line 45 "fd-stream.vala"
	return result;
#line 301 "fd-stream.c"
}

static gssize
fd_output_stream_real_write (GOutputStream* base,
                             guint8* buffer,
                             gsize buffer_length1,
                             GCancellable* cancellable,
                             GError** error)
{
	FdOutputStream * self;
	gssize result;
#line 48 "fd-stream.vala"
	self = (FdOutputStream*) base;
#line 49 "fd-stream.vala"
	result = write (self->priv->fd, buffer, (gsize) buffer_length1);
#line 49 "fd-stream.vala"
	return result;
#line 319 "fd-stream.c"
}

static void
fd_output_stream_class_init (FdOutputStreamClass * klass,
                             gpointer klass_data)
{
#line 37 "fd-stream.vala"
	fd_output_stream_parent_class = g_type_class_peek_parent (klass);
#line 37 "fd-stream.vala"
	g_type_class_adjust_private_offset (klass, &FdOutputStream_private_offset);
#line 37 "fd-stream.vala"
	((GOutputStreamClass *) klass)->close_fn = (gboolean (*) (GOutputStream*, GCancellable*, GError**)) fd_output_stream_real_close;
#line 37 "fd-stream.vala"
	((GOutputStreamClass *) klass)->write_fn = (gssize (*) (GOutputStream*, guint8*, gsize, GCancellable*, GError**)) fd_output_stream_real_write;
#line 37 "fd-stream.vala"
	G_OBJECT_CLASS (klass)->finalize = fd_output_stream_finalize;
#line 336 "fd-stream.c"
}

static void
fd_output_stream_instance_init (FdOutputStream * self,
                                gpointer klass)
{
#line 37 "fd-stream.vala"
	self->priv = fd_output_stream_get_instance_private (self);
#line 345 "fd-stream.c"
}

static void
fd_output_stream_finalize (GObject * obj)
{
	FdOutputStream * self;
#line 37 "fd-stream.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FD_OUTPUT_STREAM, FdOutputStream);
#line 37 "fd-stream.vala"
	G_OBJECT_CLASS (fd_output_stream_parent_class)->finalize (obj);
#line 356 "fd-stream.c"
}

static GType
fd_output_stream_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FdOutputStreamClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fd_output_stream_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FdOutputStream), 0, (GInstanceInitFunc) fd_output_stream_instance_init, NULL };
	GType fd_output_stream_type_id;
	fd_output_stream_type_id = g_type_register_static (g_output_stream_get_type (), "FdOutputStream", &g_define_type_info, 0);
	FdOutputStream_private_offset = g_type_add_instance_private (fd_output_stream_type_id, sizeof (FdOutputStreamPrivate));
	return fd_output_stream_type_id;
}

GType
fd_output_stream_get_type (void)
{
	static volatile gsize fd_output_stream_type_id__once = 0;
	if (g_once_init_enter (&fd_output_stream_type_id__once)) {
		GType fd_output_stream_type_id;
		fd_output_stream_type_id = fd_output_stream_get_type_once ();
		g_once_init_leave (&fd_output_stream_type_id__once, fd_output_stream_type_id);
	}
	return fd_output_stream_type_id__once;
}

