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

/* Slurp a file.*/
/**/
/* © 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 <stdlib.h>
#include <string.h>
#include <glib.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

VALA_EXTERN gchar* slurp (GInputStream* stream,
              GError** error);
static guint8* _vala_array_dup3 (guint8* self,
                          gssize length);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static guint8*
_vala_array_dup3 (guint8* self,
                  gssize length)
{
#line 32 "slurp.vala"
	if (length > 0) {
#line 32 "slurp.vala"
		return _vala_memdup2 (self, length * sizeof (guint8));
#line 60 "slurp.c"
	}
#line 32 "slurp.vala"
	return NULL;
#line 64 "slurp.c"
}

gchar*
slurp (GInputStream* stream,
       GError** error)
{
	guint8* data = NULL;
	guint8* _tmp0_;
	gint data_length1;
	gint _data_size_;
	gulong buf_size = 0UL;
	guint8* buf = NULL;
	guint8* _tmp1_;
	gint buf_length1;
	gint _buf_size_;
	gssize bytes = 0L;
	gulong total = 0UL;
	const gchar* _tmp12_ = NULL;
	gchar* _tmp14_;
	GError* _inner_error0_ = NULL;
	gchar* result;
#line 19 "slurp.vala"
	g_return_val_if_fail (stream != NULL, NULL);
#line 20 "slurp.vala"
	_tmp0_ = g_new0 (guint8, 0);
#line 20 "slurp.vala"
	data = _tmp0_;
#line 20 "slurp.vala"
	data_length1 = 0;
#line 20 "slurp.vala"
	_data_size_ = data_length1;
#line 21 "slurp.vala"
	buf_size = (gulong) 65536;
#line 22 "slurp.vala"
	_tmp1_ = g_new0 (guint8, buf_size);
#line 22 "slurp.vala"
	buf = _tmp1_;
#line 22 "slurp.vala"
	buf_length1 = buf_size;
#line 22 "slurp.vala"
	_buf_size_ = buf_length1;
#line 24 "slurp.vala"
	total = (gulong) 0;
#line 25 "slurp.vala"
	while (TRUE) {
#line 110 "slurp.c"
		gssize _tmp2_ = 0L;
		guint8* _tmp3_;
		gint _tmp3__length1;
		gulong size = 0UL;
		guint8* _tmp4_;
		gint _tmp4__length1;
		guint8* _tmp10_;
		gint _tmp10__length1;
		guint8* _tmp11_;
		gint _tmp11__length1;
#line 26 "slurp.vala"
		_tmp3_ = buf;
#line 26 "slurp.vala"
		_tmp3__length1 = buf_length1;
#line 26 "slurp.vala"
		_tmp2_ = g_input_stream_read (stream, _tmp3_, (gsize) _tmp3__length1, NULL, &_inner_error0_);
#line 26 "slurp.vala"
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
#line 26 "slurp.vala"
			g_propagate_error (error, _inner_error0_);
#line 26 "slurp.vala"
			buf = (g_free (buf), NULL);
#line 26 "slurp.vala"
			data = (g_free (data), NULL);
#line 26 "slurp.vala"
			return NULL;
#line 137 "slurp.c"
		}
#line 26 "slurp.vala"
		bytes = _tmp2_;
#line 27 "slurp.vala"
		if (bytes <= ((gssize) 0)) {
#line 28 "slurp.vala"
			break;
#line 145 "slurp.c"
		}
#line 29 "slurp.vala"
		size = (gulong) (total + bytes);
#line 30 "slurp.vala"
		_tmp4_ = data;
#line 30 "slurp.vala"
		_tmp4__length1 = data_length1;
#line 30 "slurp.vala"
		if (size > ((gulong) _tmp4__length1)) {
#line 155 "slurp.c"
			gulong new_len = 0UL;
			guint8* prev = NULL;
			guint8* _tmp5_;
			gint _tmp5__length1;
			guint8* _tmp6_;
			gint _tmp6__length1;
			gint prev_length1;
			gint _prev_size_;
			guint8* _tmp7_;
			guint8* _tmp8_;
			gint _tmp8__length1;
			guint8* _tmp9_;
			gint _tmp9__length1;
#line 31 "slurp.vala"
			new_len = buf_size * 2;
#line 32 "slurp.vala"
			_tmp5_ = data;
#line 32 "slurp.vala"
			_tmp5__length1 = data_length1;
#line 32 "slurp.vala"
			_tmp6_ = (_tmp5_ != NULL) ? _vala_array_dup3 (_tmp5_, _tmp5__length1) : _tmp5_;
#line 32 "slurp.vala"
			_tmp6__length1 = _tmp5__length1;
#line 32 "slurp.vala"
			prev = _tmp6_;
#line 32 "slurp.vala"
			prev_length1 = _tmp6__length1;
#line 32 "slurp.vala"
			_prev_size_ = prev_length1;
#line 33 "slurp.vala"
			_tmp7_ = g_new0 (guint8, new_len);
#line 33 "slurp.vala"
			data = (g_free (data), NULL);
#line 33 "slurp.vala"
			data = _tmp7_;
#line 33 "slurp.vala"
			data_length1 = new_len;
#line 33 "slurp.vala"
			_data_size_ = data_length1;
#line 34 "slurp.vala"
			_tmp8_ = data;
#line 34 "slurp.vala"
			_tmp8__length1 = data_length1;
#line 34 "slurp.vala"
			_tmp9_ = prev;
#line 34 "slurp.vala"
			_tmp9__length1 = prev_length1;
#line 34 "slurp.vala"
			memcpy (&_tmp8_[0], &_tmp9_[0], (gsize) total);
#line 35 "slurp.vala"
			prev = (g_free (prev), NULL);
#line 35 "slurp.vala"
			prev = NULL;
#line 35 "slurp.vala"
			prev_length1 = 0;
#line 35 "slurp.vala"
			_prev_size_ = prev_length1;
#line 30 "slurp.vala"
			prev = (g_free (prev), NULL);
#line 215 "slurp.c"
		}
#line 37 "slurp.vala"
		_tmp10_ = data;
#line 37 "slurp.vala"
		_tmp10__length1 = data_length1;
#line 37 "slurp.vala"
		_tmp11_ = buf;
#line 37 "slurp.vala"
		_tmp11__length1 = buf_length1;
#line 37 "slurp.vala"
		memcpy ((&_tmp10_[0]) + total, &_tmp11_[0], (gsize) bytes);
#line 38 "slurp.vala"
		total += (gulong) bytes;
#line 229 "slurp.c"
	}
#line 40 "slurp.vala"
	if (total == ((gulong) 0)) {
#line 40 "slurp.vala"
		_tmp12_ = "";
#line 235 "slurp.c"
	} else {
		guint8* _tmp13_;
		gint _tmp13__length1;
#line 40 "slurp.vala"
		_tmp13_ = data;
#line 40 "slurp.vala"
		_tmp13__length1 = data_length1;
#line 40 "slurp.vala"
		_tmp12_ = (const gchar*) (_tmp13_ + 0);
#line 245 "slurp.c"
	}
#line 40 "slurp.vala"
	_tmp14_ = g_strdup (_tmp12_);
#line 40 "slurp.vala"
	result = _tmp14_;
#line 40 "slurp.vala"
	buf = (g_free (buf), NULL);
#line 40 "slurp.vala"
	data = (g_free (data), NULL);
#line 40 "slurp.vala"
	return result;
#line 257 "slurp.c"
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

