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

/*
 * Copyright (C) 2012-2013 Canonical Ltd.
 * Author: Martin Pitt <martin.pitt@ubuntu.com>
 *
 * umockdev 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.
 *
 * umockdev 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 program; If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "uevent_sender.h"
#include <glib/gstdio.h>
#include <stdio.h>
#include <gio/gio.h>
#include <errno.h>
#include <stdarg.h>


#define UMOCKDEV_TYPE_TESTBED (umockdev_testbed_get_type ())
#define UMOCKDEV_TESTBED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UMOCKDEV_TYPE_TESTBED, UMockdevTestbed))
#define UMOCKDEV_TESTBED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UMOCKDEV_TYPE_TESTBED, UMockdevTestbedClass))
#define UMOCKDEV_IS_TESTBED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UMOCKDEV_TYPE_TESTBED))
#define UMOCKDEV_IS_TESTBED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UMOCKDEV_TYPE_TESTBED))
#define UMOCKDEV_TESTBED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UMOCKDEV_TYPE_TESTBED, UMockdevTestbedClass))

typedef struct _UMockdevTestbed UMockdevTestbed;
typedef struct _UMockdevTestbedClass UMockdevTestbedClass;
typedef struct _UMockdevTestbedPrivate UMockdevTestbedPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _uevent_sender_close0(var) ((var == NULL) ? NULL : (var = (uevent_sender_close (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_match_info_free0(var) ((var == NULL) ? NULL : (var = (g_match_info_free (var), NULL)))
#define _g_dir_close0(var) ((var == NULL) ? NULL : (var = (g_dir_close (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _UMockdevTestbed {
	GObject parent_instance;
	UMockdevTestbedPrivate * priv;
};

struct _UMockdevTestbedClass {
	GObjectClass parent_class;
};

struct _UMockdevTestbedPrivate {
	gchar* root_dir;
	gchar* sys_dir;
	GRegex* re_record_val;
	GRegex* re_record_keyval;
	GRegex* re_record_optval;
	uevent_sender* ev_sender;
};

typedef enum  {
	UMOCKDEV_ERROR_PARSE,
	UMOCKDEV_ERROR_VALUE
} UMockdevError;
#define UMOCKDEV_ERROR umockdev_error_quark ()

static gpointer umockdev_testbed_parent_class = NULL;

GType umockdev_testbed_get_type (void) G_GNUC_CONST;
#define UMOCKDEV_TESTBED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UMOCKDEV_TYPE_TESTBED, UMockdevTestbedPrivate))
enum  {
	UMOCKDEV_TESTBED_DUMMY_PROPERTY
};
void umockdev_remove_dir (const gchar* path);
UMockdevTestbed* umockdev_testbed_new (void);
UMockdevTestbed* umockdev_testbed_construct (GType object_type);
gchar* umockdev_testbed_get_root_dir (UMockdevTestbed* self);
gchar* umockdev_testbed_get_sys_dir (UMockdevTestbed* self);
void umockdev_testbed_set_attribute (UMockdevTestbed* self, const gchar* devpath, const gchar* name, const gchar* value);
void umockdev_testbed_set_attribute_binary (UMockdevTestbed* self, const gchar* devpath, const gchar* name, guint8* value, int value_length1);
void umockdev_testbed_set_attribute_int (UMockdevTestbed* self, const gchar* devpath, const gchar* name, gint value);
void umockdev_testbed_set_attribute_hex (UMockdevTestbed* self, const gchar* devpath, const gchar* name, guint value);
void umockdev_testbed_set_property (UMockdevTestbed* self, const gchar* devpath, const gchar* name, const gchar* value);
void umockdev_testbed_set_property_int (UMockdevTestbed* self, const gchar* devpath, const gchar* name, gint value);
void umockdev_testbed_set_property_hex (UMockdevTestbed* self, const gchar* devpath, const gchar* name, guint value);
gchar* umockdev_testbed_add_devicev (UMockdevTestbed* self, const gchar* subsystem, const gchar* name, const gchar* parent, gchar** attributes, gchar** properties);
gchar* umockdev_make_dotdots (const gchar* path);
gchar* umockdev_testbed_add_device (UMockdevTestbed* self, const gchar* subsystem, const gchar* name, const gchar* parent, ...);
static void _vala_array_add1 (gchar*** array, int* length, int* size, gchar* value);
static void _vala_array_add2 (gchar*** array, int* length, int* size, gchar* value);
GQuark umockdev_error_quark (void);
gboolean umockdev_testbed_add_from_string (UMockdevTestbed* self, const gchar* data, GError** error);
static gchar* umockdev_testbed_add_dev_from_string (UMockdevTestbed* self, const gchar* data, GError** error);
void umockdev_testbed_uevent (UMockdevTestbed* self, const gchar* devpath, const gchar* action);
gboolean umockdev_testbed_load_ioctl (UMockdevTestbed* self, const gchar* dev, const gchar* recordfile, GError** error);
static gchar* umockdev_testbed_record_parse_line (UMockdevTestbed* self, const gchar* data, gchar* type, gchar** key, gchar** val);
static void _vala_array_add3 (gchar*** array, int* length, int* size, gchar* value);
static void _vala_array_add4 (gchar*** array, int* length, int* size, gchar* value);
static void _vala_array_add5 (gchar*** array, int* length, int* size, gchar* value);
static void _vala_array_add6 (gchar*** array, int* length, int* size, gchar* value);
static void _vala_array_add7 (gchar*** array, int* length, int* size, gchar* value);
static void _vala_array_add8 (gchar*** array, int* length, int* size, gchar* value);
guint8* umockdev_decode_hex (const gchar* data, int* result_length1, GError** error);
static void umockdev_testbed_finalize (GObject* obj);
guint8 umockdev_hexdigit (gchar c);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);

static GRegex* _tmp_regex_0 = NULL;
static GRegex* _tmp_regex_1 = NULL;
static GRegex* _tmp_regex_2 = NULL;

UMockdevTestbed* umockdev_testbed_construct (GType object_type) {
	UMockdevTestbed * self = NULL;
	const gchar* _tmp4_;
	gchar* _tmp5_ = NULL;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	GError * _inner_error_ = NULL;
	self = (UMockdevTestbed*) g_object_new (object_type, NULL);
	{
		gchar* _tmp0_ = NULL;
		gchar* _tmp1_;
		_tmp0_ = g_dir_make_tmp ("umockdev.XXXXXX", &_inner_error_);
		_tmp1_ = _tmp0_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch0_g_file_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_g_free0 (self->priv->root_dir);
		self->priv->root_dir = _tmp1_;
	}
	goto __finally0;
	__catch0_g_file_error:
	{
		GError* e = NULL;
		FILE* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp2_ = stderr;
		_tmp3_ = e->message;
		fprintf (_tmp2_, "Cannot create temporary directory: %s\n", _tmp3_);
		abort ();
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp4_ = self->priv->root_dir;
	_tmp5_ = g_build_filename (_tmp4_, "sys", NULL);
	_g_free0 (self->priv->sys_dir);
	self->priv->sys_dir = _tmp5_;
	_tmp6_ = self->priv->sys_dir;
	g_mkdir (_tmp6_, 0755);
	_tmp7_ = self->priv->root_dir;
	g_setenv ("UMOCKDEV_DIR", _tmp7_, TRUE);
	_tmp8_ = self->priv->root_dir;
	g_debug ("umockdev.vala:60: Created udev test bed %s", _tmp8_);
	return self;
}


UMockdevTestbed* umockdev_testbed_new (void) {
	return umockdev_testbed_construct (UMOCKDEV_TYPE_TESTBED);
}


/**
     * umockdev_testbed_get_root_dir:
     * @self: A #UMockdevTestbed.
     * 
     * Get the root directory for the testbed.
     *
     * Returns: The testbed's root directory.
     */
gchar* umockdev_testbed_get_root_dir (UMockdevTestbed* self) {
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->root_dir;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}


/**
     * umockdev_testbed_get_sys_dir:
     * @self: A #UMockdevTestbed.
     * 
     * Get the sysfs directory for the testbed.
     *
     * Returns: The testbed's sysfs directory.
     */
gchar* umockdev_testbed_get_sys_dir (UMockdevTestbed* self) {
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->sys_dir;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}


static guint8* string_get_data (const gchar* self, int* result_length1) {
	guint8* result;
	guint8* res;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	guint8* _tmp3_;
	gint _tmp3__length1;
	guint8* _tmp4_;
	gint _tmp4__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res_length1;
	_tmp3_ = res;
	_tmp3__length1 = res_length1;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = _tmp3__length1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}


void umockdev_testbed_set_attribute (UMockdevTestbed* self, const gchar* devpath, const gchar* name, const gchar* value) {
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	guint8* _tmp3_;
	gint _tmp3__length1;
	guint8* _tmp4_;
	gint _tmp4__length1;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = devpath;
	_tmp1_ = name;
	_tmp2_ = value;
	_tmp3_ = string_get_data (_tmp2_, &_tmp3__length1);
	_tmp4_ = _tmp3_;
	_tmp4__length1 = _tmp3__length1;
	umockdev_testbed_set_attribute_binary (self, _tmp0_, _tmp1_, _tmp4_, _tmp4__length1);
}


void umockdev_testbed_set_attribute_binary (UMockdevTestbed* self, const gchar* devpath, const gchar* name, guint8* value, int value_length1) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (name != NULL);
	{
		const gchar* _tmp0_;
		const gchar* _tmp1_;
		const gchar* _tmp2_;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_;
		guint8* _tmp5_;
		gint _tmp5__length1;
		_tmp0_ = self->priv->root_dir;
		_tmp1_ = devpath;
		_tmp2_ = name;
		_tmp3_ = g_build_filename (_tmp0_, _tmp1_, _tmp2_, NULL);
		_tmp4_ = _tmp3_;
		_tmp5_ = value;
		_tmp5__length1 = value_length1;
		g_file_set_contents (_tmp4_, (const char*) _tmp5_, (size_t) _tmp5__length1, &_inner_error_);
		_g_free0 (_tmp4_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch1_g_file_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	goto __finally1;
	__catch1_g_file_error:
	{
		GError* e = NULL;
		FILE* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = stderr;
		_tmp7_ = e->message;
		fprintf (_tmp6_, "Cannot write attribute file: %s\n", _tmp7_);
		abort ();
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


void umockdev_testbed_set_attribute_int (UMockdevTestbed* self, const gchar* devpath, const gchar* name, gint value) {
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gint _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = devpath;
	_tmp1_ = name;
	_tmp2_ = value;
	_tmp3_ = g_strdup_printf ("%i", _tmp2_);
	_tmp4_ = _tmp3_;
	umockdev_testbed_set_attribute (self, _tmp0_, _tmp1_, _tmp4_);
	_g_free0 (_tmp4_);
}


void umockdev_testbed_set_attribute_hex (UMockdevTestbed* self, const gchar* devpath, const gchar* name, guint value) {
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	guint _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = devpath;
	_tmp1_ = name;
	_tmp2_ = value;
	_tmp3_ = g_strdup_printf ("%x", _tmp2_);
	_tmp4_ = _tmp3_;
	umockdev_testbed_set_attribute (self, _tmp0_, _tmp1_, _tmp4_);
	_g_free0 (_tmp4_);
}


static glong string_strnlen (gchar* str, glong maxlen) {
	glong result = 0L;
	gchar* _tmp0_;
	glong _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* end;
	gchar* _tmp3_;
	_tmp0_ = str;
	_tmp1_ = maxlen;
	_tmp2_ = memchr (_tmp0_, 0, (gsize) _tmp1_);
	end = _tmp2_;
	_tmp3_ = end;
	if (_tmp3_ == NULL) {
		glong _tmp4_;
		_tmp4_ = maxlen;
		result = _tmp4_;
		return result;
	} else {
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = end;
		_tmp6_ = str;
		result = (glong) (_tmp5_ - _tmp6_);
		return result;
	}
}


static gchar* string_substring (const gchar* self, glong offset, glong len) {
	gchar* result = NULL;
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	glong _tmp1_;
	gboolean _tmp3_;
	glong _tmp9_;
	glong _tmp15_;
	glong _tmp18_;
	glong _tmp19_;
	glong _tmp20_;
	glong _tmp21_;
	glong _tmp22_;
	gchar* _tmp23_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = offset;
	if (_tmp1_ >= ((glong) 0)) {
		glong _tmp2_;
		_tmp2_ = len;
		_tmp0_ = _tmp2_ >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	_tmp3_ = _tmp0_;
	if (_tmp3_) {
		glong _tmp4_;
		glong _tmp5_;
		glong _tmp6_ = 0L;
		_tmp4_ = offset;
		_tmp5_ = len;
		_tmp6_ = string_strnlen ((gchar*) self, _tmp4_ + _tmp5_);
		string_length = _tmp6_;
	} else {
		gint _tmp7_;
		gint _tmp8_;
		_tmp7_ = strlen (self);
		_tmp8_ = _tmp7_;
		string_length = (glong) _tmp8_;
	}
	_tmp9_ = offset;
	if (_tmp9_ < ((glong) 0)) {
		glong _tmp10_;
		glong _tmp11_;
		glong _tmp12_;
		_tmp10_ = string_length;
		_tmp11_ = offset;
		offset = _tmp10_ + _tmp11_;
		_tmp12_ = offset;
		g_return_val_if_fail (_tmp12_ >= ((glong) 0), NULL);
	} else {
		glong _tmp13_;
		glong _tmp14_;
		_tmp13_ = offset;
		_tmp14_ = string_length;
		g_return_val_if_fail (_tmp13_ <= _tmp14_, NULL);
	}
	_tmp15_ = len;
	if (_tmp15_ < ((glong) 0)) {
		glong _tmp16_;
		glong _tmp17_;
		_tmp16_ = string_length;
		_tmp17_ = offset;
		len = _tmp16_ - _tmp17_;
	}
	_tmp18_ = offset;
	_tmp19_ = len;
	_tmp20_ = string_length;
	g_return_val_if_fail ((_tmp18_ + _tmp19_) <= _tmp20_, NULL);
	_tmp21_ = offset;
	_tmp22_ = len;
	_tmp23_ = g_strndup (((gchar*) self) + _tmp21_, (gsize) _tmp22_);
	result = _tmp23_;
	return result;
}


void umockdev_testbed_set_property (UMockdevTestbed* self, const gchar* devpath, const gchar* name, const gchar* value) {
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* uevent_path;
	gchar* _tmp3_;
	gchar* props;
	gchar* real_value = NULL;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	gboolean _tmp8_;
	const gchar* _tmp13_;
	GFile* _tmp14_ = NULL;
	GFile* f;
	gboolean existing;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* prefix;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = self->priv->root_dir;
	_tmp1_ = devpath;
	_tmp2_ = g_build_filename (_tmp0_, _tmp1_, "uevent", NULL);
	uevent_path = _tmp2_;
	_tmp3_ = g_strdup ("");
	props = _tmp3_;
	_tmp5_ = name;
	if (g_strcmp0 (_tmp5_, "DEVNAME") == 0) {
		const gchar* _tmp6_;
		gboolean _tmp7_ = FALSE;
		_tmp6_ = value;
		_tmp7_ = g_str_has_prefix (_tmp6_, "/dev/");
		_tmp4_ = _tmp7_;
	} else {
		_tmp4_ = FALSE;
	}
	_tmp8_ = _tmp4_;
	if (_tmp8_) {
		const gchar* _tmp9_;
		gchar* _tmp10_ = NULL;
		_tmp9_ = value;
		_tmp10_ = string_substring (_tmp9_, (glong) 5, (glong) (-1));
		_g_free0 (real_value);
		real_value = _tmp10_;
	} else {
		const gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp11_ = value;
		_tmp12_ = g_strdup (_tmp11_);
		_g_free0 (real_value);
		real_value = _tmp12_;
	}
	_tmp13_ = uevent_path;
	_tmp14_ = g_file_new_for_path (_tmp13_);
	f = _tmp14_;
	existing = FALSE;
	_tmp15_ = name;
	_tmp16_ = g_strconcat (_tmp15_, "=", NULL);
	prefix = _tmp16_;
	{
		GFile* _tmp17_;
		GFileInputStream* _tmp18_ = NULL;
		GFileInputStream* _tmp19_;
		GFileInputStream* _tmp20_;
		GDataInputStream* _tmp21_;
		GDataInputStream* _tmp22_;
		GDataInputStream* inp;
		gchar* line = NULL;
		gsize len = 0UL;
		GDataInputStream* _tmp44_;
		gboolean _tmp45_;
		const gchar* _tmp54_;
		const gchar* _tmp55_;
		guint8* _tmp56_;
		gint _tmp56__length1;
		guint8* _tmp57_;
		gint _tmp57__length1;
		_tmp17_ = f;
		_tmp18_ = g_file_read (_tmp17_, NULL, &_inner_error_);
		_tmp19_ = _tmp18_;
		if (_inner_error_ != NULL) {
			goto __catch2_g_error;
		}
		_tmp20_ = _tmp19_;
		_tmp21_ = g_data_input_stream_new ((GInputStream*) _tmp20_);
		_tmp22_ = _tmp21_;
		_g_object_unref0 (_tmp20_);
		inp = _tmp22_;
		while (TRUE) {
			GDataInputStream* _tmp23_;
			gsize _tmp24_ = 0UL;
			gchar* _tmp25_ = NULL;
			gchar* _tmp26_;
			const gchar* _tmp27_;
			const gchar* _tmp28_;
			const gchar* _tmp29_;
			gboolean _tmp30_ = FALSE;
			_tmp23_ = inp;
			_tmp25_ = g_data_input_stream_read_line (_tmp23_, &_tmp24_, NULL, &_inner_error_);
			len = _tmp24_;
			_tmp26_ = _tmp25_;
			if (_inner_error_ != NULL) {
				_g_free0 (line);
				_g_object_unref0 (inp);
				goto __catch2_g_error;
			}
			_g_free0 (line);
			line = _tmp26_;
			_tmp27_ = line;
			if (!(_tmp27_ != NULL)) {
				break;
			}
			_tmp28_ = line;
			_tmp29_ = prefix;
			_tmp30_ = g_str_has_prefix (_tmp28_, _tmp29_);
			if (_tmp30_) {
				const gchar* _tmp31_;
				const gchar* _tmp32_;
				const gchar* _tmp33_;
				gchar* _tmp34_;
				gchar* _tmp35_;
				gchar* _tmp36_;
				gchar* _tmp37_;
				gchar* _tmp38_;
				existing = TRUE;
				_tmp31_ = props;
				_tmp32_ = prefix;
				_tmp33_ = real_value;
				_tmp34_ = g_strconcat (_tmp32_, _tmp33_, NULL);
				_tmp35_ = _tmp34_;
				_tmp36_ = g_strconcat (_tmp35_, "\n", NULL);
				_tmp37_ = _tmp36_;
				_tmp38_ = g_strconcat (_tmp31_, _tmp37_, NULL);
				_g_free0 (props);
				props = _tmp38_;
				_g_free0 (_tmp37_);
				_g_free0 (_tmp35_);
			} else {
				const gchar* _tmp39_;
				const gchar* _tmp40_;
				gchar* _tmp41_;
				gchar* _tmp42_;
				gchar* _tmp43_;
				_tmp39_ = props;
				_tmp40_ = line;
				_tmp41_ = g_strconcat (_tmp40_, "\n", NULL);
				_tmp42_ = _tmp41_;
				_tmp43_ = g_strconcat (_tmp39_, _tmp42_, NULL);
				_g_free0 (props);
				props = _tmp43_;
				_g_free0 (_tmp42_);
			}
		}
		_tmp44_ = inp;
		g_input_stream_close ((GInputStream*) _tmp44_, NULL, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_free0 (line);
			_g_object_unref0 (inp);
			goto __catch2_g_error;
		}
		_tmp45_ = existing;
		if (!_tmp45_) {
			const gchar* _tmp46_;
			const gchar* _tmp47_;
			const gchar* _tmp48_;
			gchar* _tmp49_;
			gchar* _tmp50_;
			gchar* _tmp51_;
			gchar* _tmp52_;
			gchar* _tmp53_;
			_tmp46_ = props;
			_tmp47_ = prefix;
			_tmp48_ = real_value;
			_tmp49_ = g_strconcat (_tmp47_, _tmp48_, NULL);
			_tmp50_ = _tmp49_;
			_tmp51_ = g_strconcat (_tmp50_, "\n", NULL);
			_tmp52_ = _tmp51_;
			_tmp53_ = g_strconcat (_tmp46_, _tmp52_, NULL);
			_g_free0 (props);
			props = _tmp53_;
			_g_free0 (_tmp52_);
			_g_free0 (_tmp50_);
		}
		_tmp54_ = uevent_path;
		_tmp55_ = props;
		_tmp56_ = string_get_data (_tmp55_, &_tmp56__length1);
		_tmp57_ = _tmp56_;
		_tmp57__length1 = _tmp56__length1;
		g_file_set_contents (_tmp54_, (const char*) _tmp57_, (size_t) _tmp57__length1, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_free0 (line);
			_g_object_unref0 (inp);
			goto __catch2_g_error;
		}
		_g_free0 (line);
		_g_object_unref0 (inp);
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
		FILE* _tmp58_;
		const gchar* _tmp59_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp58_ = stderr;
		_tmp59_ = e->message;
		fprintf (_tmp58_, "Cannot update uevent file: %s\n", _tmp59_);
		abort ();
		_g_error_free0 (e);
	}
	__finally2:
	if (_inner_error_ != NULL) {
		_g_free0 (prefix);
		_g_object_unref0 (f);
		_g_free0 (real_value);
		_g_free0 (props);
		_g_free0 (uevent_path);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_g_free0 (prefix);
	_g_object_unref0 (f);
	_g_free0 (real_value);
	_g_free0 (props);
	_g_free0 (uevent_path);
}


void umockdev_testbed_set_property_int (UMockdevTestbed* self, const gchar* devpath, const gchar* name, gint value) {
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gint _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = devpath;
	_tmp1_ = name;
	_tmp2_ = value;
	_tmp3_ = g_strdup_printf ("%i", _tmp2_);
	_tmp4_ = _tmp3_;
	umockdev_testbed_set_property (self, _tmp0_, _tmp1_, _tmp4_);
	_g_free0 (_tmp4_);
}


void umockdev_testbed_set_property_hex (UMockdevTestbed* self, const gchar* devpath, const gchar* name, guint value) {
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	guint _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = devpath;
	_tmp1_ = name;
	_tmp2_ = value;
	_tmp3_ = g_strdup_printf ("%x", _tmp2_);
	_tmp4_ = _tmp3_;
	umockdev_testbed_set_property (self, _tmp0_, _tmp1_, _tmp4_);
	_g_free0 (_tmp4_);
}


/**
     * umockdev_testbed_add_devicev:
     * @self: A #UMockdevTestbed.
     * @subsystem: The subsystem name, e. g. "usb"
     * @name: The device name; arbitrary, but needs to be unique within the testbed
     * @parent: (allow-none): device path of the parent device. Use %NULL for a
     *          top-level device.
     * @attributes: (array zero-terminated=1):
     *              A list of device sysfs attributes, alternating names and
     *              values, terminated with %NULL:
     *              { "key1", "value1", "key2", "value2", ..., NULL }
     * @properties: (array zero-terminated=1):
     *              A list of device udev properties; same format as @attributes
     *
     * This method is mostly meant for language bindings (where it is named
     * umockdev_testbed_add_device()). For C programs it is usually more convenient to
     * use umockdev_testbed_add_device().
     *
     * Add a new device to the testbed. A Linux kernel device always has a
     * subsystem (such as "usb" or "pci"), and a device name. The test bed only
     * builds a very simple sysfs structure without nested namespaces, so it
     * requires device names to be unique. Some gudev client programs might make
     * assumptions about the name (e. g. a SCSI disk block device should be called
     * sdaN). A device also has an arbitrary number of sysfs attributes and udev
     * properties; usually you should specify them upon creation, but it is also
     * possible to change them later on with umockdev_testbed_set_attribute() and
     * umockdev_testbed_set_property().
     *
     * Returns: The sysfs path for the newly created device. Free with g_free().
     *
     * Rename to: umockdev_testbed_add_device
     */
static gint string_index_of (const gchar* self, const gchar* needle, gint start_index) {
	gint result = 0;
	gint _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _result_;
	gchar* _tmp3_;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (needle != NULL, 0);
	_tmp0_ = start_index;
	_tmp1_ = needle;
	_tmp2_ = strstr (((gchar*) self) + _tmp0_, (gchar*) _tmp1_);
	_result_ = _tmp2_;
	_tmp3_ = _result_;
	if (_tmp3_ != NULL) {
		gchar* _tmp4_;
		_tmp4_ = _result_;
		result = (gint) (_tmp4_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}


gchar* umockdev_testbed_add_devicev (UMockdevTestbed* self, const gchar* subsystem, const gchar* name, const gchar* parent, gchar** attributes, gchar** properties) {
	gchar* result = NULL;
	gchar* dev_path = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_ = NULL;
	gchar* dev_dir;
	gboolean _tmp12_ = FALSE;
	const gchar* _tmp13_;
	gboolean _tmp14_ = FALSE;
	gboolean _tmp19_;
	const gchar* _tmp21_;
	gint _tmp22_ = 0;
	const gchar* _tmp26_;
	const gchar* _tmp27_;
	gchar* _tmp28_ = NULL;
	gchar* class_dir;
	const gchar* _tmp29_;
	gint _tmp30_ = 0;
	const gchar* _tmp34_;
	const gchar* _tmp35_;
	gint _tmp36_ = 0;
	gchar* _tmp37_ = NULL;
	gchar* dev_path_no_sys;
	const gchar* _tmp38_;
	gchar* _tmp39_ = NULL;
	gchar* _tmp40_;
	const gchar* _tmp41_;
	gchar* _tmp42_ = NULL;
	gchar* _tmp43_;
	const gchar* _tmp44_;
	gchar* _tmp45_ = NULL;
	gchar* _tmp46_;
	gint _tmp47_ = 0;
	const gchar* _tmp48_;
	gchar* _tmp49_ = NULL;
	gchar* _tmp50_;
	const gchar* _tmp51_;
	const gchar* _tmp52_;
	gchar* _tmp53_ = NULL;
	gchar* _tmp54_;
	gchar* _tmp55_ = NULL;
	gchar* _tmp56_;
	gint _tmp57_ = 0;
	gboolean _tmp58_ = FALSE;
	const gchar* _tmp59_;
	gboolean _tmp61_;
	gchar** _tmp89_;
	gint _tmp89__length1;
	gchar* _tmp93_;
	gchar* props;
	gchar** _tmp133_;
	gint _tmp133__length1;
	const gchar* _tmp137_;
	const gchar* _tmp138_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (subsystem != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = parent;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		gboolean _tmp2_ = FALSE;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_ = NULL;
		_tmp1_ = parent;
		_tmp2_ = g_file_test (_tmp1_, G_FILE_TEST_IS_DIR);
		if (!_tmp2_) {
			const gchar* _tmp3_;
			_tmp3_ = parent;
			g_critical ("umockdev.vala:215: add_devicev(): parent device %s does not exist", _tmp3_);
			result = NULL;
			_g_free0 (dev_path);
			return result;
		}
		_tmp4_ = parent;
		_tmp5_ = name;
		_tmp6_ = g_build_filename (_tmp4_, _tmp5_, NULL);
		_g_free0 (dev_path);
		dev_path = _tmp6_;
	} else {
		const gchar* _tmp7_;
		gchar* _tmp8_ = NULL;
		_tmp7_ = name;
		_tmp8_ = g_build_filename ("/sys/devices", _tmp7_, NULL);
		_g_free0 (dev_path);
		dev_path = _tmp8_;
	}
	_tmp9_ = self->priv->root_dir;
	_tmp10_ = dev_path;
	_tmp11_ = g_build_filename (_tmp9_, _tmp10_, NULL);
	dev_dir = _tmp11_;
	_tmp13_ = dev_dir;
	_tmp14_ = g_file_test (_tmp13_, G_FILE_TEST_EXISTS);
	if (_tmp14_) {
		const gchar* _tmp15_;
		gchar* _tmp16_ = NULL;
		gchar* _tmp17_;
		gboolean _tmp18_ = FALSE;
		_tmp15_ = dev_dir;
		_tmp16_ = g_build_filename (_tmp15_, "uevent", NULL);
		_tmp17_ = _tmp16_;
		_tmp18_ = g_file_test (_tmp17_, G_FILE_TEST_EXISTS);
		_tmp12_ = _tmp18_;
		_g_free0 (_tmp17_);
	} else {
		_tmp12_ = FALSE;
	}
	_tmp19_ = _tmp12_;
	if (_tmp19_) {
		const gchar* _tmp20_;
		_tmp20_ = dev_dir;
		g_error ("umockdev.vala:226: device %s already exists", _tmp20_);
	}
	_tmp21_ = dev_dir;
	_tmp22_ = g_mkdir_with_parents (_tmp21_, 0755);
	if (_tmp22_ != 0) {
		const gchar* _tmp23_;
		gint _tmp24_;
		const gchar* _tmp25_ = NULL;
		_tmp23_ = dev_dir;
		_tmp24_ = errno;
		_tmp25_ = g_strerror (_tmp24_);
		g_error ("umockdev.vala:230: cannot create dev dir '%s': %s", _tmp23_, _tmp25_);
	}
	_tmp26_ = self->priv->sys_dir;
	_tmp27_ = subsystem;
	_tmp28_ = g_build_filename (_tmp26_, "class", _tmp27_, NULL);
	class_dir = _tmp28_;
	_tmp29_ = class_dir;
	_tmp30_ = g_mkdir_with_parents (_tmp29_, 0755);
	if (_tmp30_ != 0) {
		const gchar* _tmp31_;
		gint _tmp32_;
		const gchar* _tmp33_ = NULL;
		_tmp31_ = class_dir;
		_tmp32_ = errno;
		_tmp33_ = g_strerror (_tmp32_);
		g_error ("umockdev.vala:233: cannot create class dir '%s': %s", _tmp31_, _tmp33_);
	}
	_tmp34_ = dev_path;
	_tmp35_ = dev_path;
	_tmp36_ = string_index_of (_tmp35_, "/devices/", 0);
	_tmp37_ = string_substring (_tmp34_, (glong) _tmp36_, (glong) (-1));
	dev_path_no_sys = _tmp37_;
	_tmp38_ = dev_path;
	_tmp39_ = umockdev_make_dotdots (_tmp38_);
	_tmp40_ = _tmp39_;
	_tmp41_ = subsystem;
	_tmp42_ = g_build_filename (_tmp40_, "class", _tmp41_, NULL);
	_tmp43_ = _tmp42_;
	_tmp44_ = dev_dir;
	_tmp45_ = g_build_filename (_tmp44_, "subsystem", NULL);
	_tmp46_ = _tmp45_;
	_tmp47_ = symlink (_tmp43_, _tmp46_);
	_vala_assert (_tmp47_ == 0, "FileUtils.symlink(Path.build_filename(make_dotdots(dev_path), \"class\", subsystem),                                  Path.build_filename(dev_dir, \"subsystem\")) == 0");
	_g_free0 (_tmp46_);
	_g_free0 (_tmp43_);
	_g_free0 (_tmp40_);
	_tmp48_ = dev_path_no_sys;
	_tmp49_ = g_build_filename ("..", "..", _tmp48_, NULL);
	_tmp50_ = _tmp49_;
	_tmp51_ = class_dir;
	_tmp52_ = name;
	_tmp53_ = g_path_get_basename (_tmp52_);
	_tmp54_ = _tmp53_;
	_tmp55_ = g_build_filename (_tmp51_, _tmp54_, NULL);
	_tmp56_ = _tmp55_;
	_tmp57_ = symlink (_tmp50_, _tmp56_);
	_vala_assert (_tmp57_ == 0, "FileUtils.symlink(Path.build_filename(\"..\", \"..\", dev_path_no_sys),                                  Path.build_filename(class_dir, Path.get_basename(name))) == 0");
	_g_free0 (_tmp56_);
	_g_free0 (_tmp54_);
	_g_free0 (_tmp50_);
	_tmp59_ = subsystem;
	if (g_strcmp0 (_tmp59_, "usb") == 0) {
		_tmp58_ = TRUE;
	} else {
		const gchar* _tmp60_;
		_tmp60_ = subsystem;
		_tmp58_ = g_strcmp0 (_tmp60_, "pci") == 0;
	}
	_tmp61_ = _tmp58_;
	if (_tmp61_) {
		const gchar* _tmp62_;
		const gchar* _tmp63_;
		gchar* _tmp64_ = NULL;
		const gchar* _tmp65_;
		gint _tmp66_ = 0;
		const gchar* _tmp67_;
		gchar* _tmp68_ = NULL;
		gchar* _tmp69_;
		const gchar* _tmp70_;
		const gchar* _tmp71_;
		gchar* _tmp72_ = NULL;
		gchar* _tmp73_;
		gchar* _tmp74_ = NULL;
		gchar* _tmp75_;
		gint _tmp76_ = 0;
		_tmp62_ = self->priv->sys_dir;
		_tmp63_ = subsystem;
		_tmp64_ = g_build_filename (_tmp62_, "bus", _tmp63_, "devices", NULL);
		_g_free0 (class_dir);
		class_dir = _tmp64_;
		_tmp65_ = class_dir;
		_tmp66_ = g_mkdir_with_parents (_tmp65_, 0755);
		_vala_assert (_tmp66_ == 0, "DirUtils.create_with_parents(class_dir, 0755) == 0");
		_tmp67_ = dev_path_no_sys;
		_tmp68_ = g_build_filename ("..", "..", "..", _tmp67_, NULL);
		_tmp69_ = _tmp68_;
		_tmp70_ = class_dir;
		_tmp71_ = name;
		_tmp72_ = g_path_get_basename (_tmp71_);
		_tmp73_ = _tmp72_;
		_tmp74_ = g_build_filename (_tmp70_, _tmp73_, NULL);
		_tmp75_ = _tmp74_;
		_tmp76_ = symlink (_tmp69_, _tmp75_);
		_vala_assert (_tmp76_ == 0, "FileUtils.symlink(Path.build_filename(\"..\", \"..\", \"..\", dev_path_no_sys),                                      Path.build_filename(class_dir, Path.get_basename(name))) == 0");
		_g_free0 (_tmp75_);
		_g_free0 (_tmp73_);
		_g_free0 (_tmp69_);
	}
	{
		gint i;
		i = 0;
		{
			gboolean _tmp77_;
			_tmp77_ = TRUE;
			while (TRUE) {
				gboolean _tmp78_;
				gint _tmp80_;
				gchar** _tmp81_;
				gint _tmp81__length1;
				const gchar* _tmp82_;
				gchar** _tmp83_;
				gint _tmp83__length1;
				gint _tmp84_;
				const gchar* _tmp85_;
				gchar** _tmp86_;
				gint _tmp86__length1;
				gint _tmp87_;
				const gchar* _tmp88_;
				_tmp78_ = _tmp77_;
				if (!_tmp78_) {
					gint _tmp79_;
					_tmp79_ = i;
					i = _tmp79_ + 2;
				}
				_tmp77_ = FALSE;
				_tmp80_ = i;
				_tmp81_ = attributes;
				_tmp81__length1 = _vala_array_length (attributes);
				if (!(_tmp80_ < (_tmp81__length1 - 1))) {
					break;
				}
				_tmp82_ = dev_path;
				_tmp83_ = attributes;
				_tmp83__length1 = _vala_array_length (attributes);
				_tmp84_ = i;
				_tmp85_ = _tmp83_[_tmp84_];
				_tmp86_ = attributes;
				_tmp86__length1 = _vala_array_length (attributes);
				_tmp87_ = i;
				_tmp88_ = _tmp86_[_tmp87_ + 1];
				umockdev_testbed_set_attribute (self, _tmp82_, _tmp85_, _tmp88_);
			}
		}
	}
	_tmp89_ = attributes;
	_tmp89__length1 = _vala_array_length (attributes);
	if ((_tmp89__length1 % 2) != 0) {
		gchar** _tmp90_;
		gint _tmp90__length1;
		gchar** _tmp91_;
		gint _tmp91__length1;
		const gchar* _tmp92_;
		_tmp90_ = attributes;
		_tmp90__length1 = _vala_array_length (attributes);
		_tmp91_ = attributes;
		_tmp91__length1 = _vala_array_length (attributes);
		_tmp92_ = _tmp90_[_tmp91__length1 - 1];
		g_warning ("umockdev.vala:258: add_devicev: Ignoring attribute key '%s' without va" \
"lue", _tmp92_);
	}
	_tmp93_ = g_strdup ("");
	props = _tmp93_;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp94_;
			_tmp94_ = TRUE;
			while (TRUE) {
				gboolean _tmp95_;
				gint _tmp97_;
				gchar** _tmp98_;
				gint _tmp98__length1;
				gboolean _tmp99_ = FALSE;
				gchar** _tmp100_;
				gint _tmp100__length1;
				gint _tmp101_;
				const gchar* _tmp102_;
				gboolean _tmp107_;
				_tmp95_ = _tmp94_;
				if (!_tmp95_) {
					gint _tmp96_;
					_tmp96_ = i;
					i = _tmp96_ + 2;
				}
				_tmp94_ = FALSE;
				_tmp97_ = i;
				_tmp98_ = properties;
				_tmp98__length1 = _vala_array_length (properties);
				if (!(_tmp97_ < (_tmp98__length1 - 1))) {
					break;
				}
				_tmp100_ = properties;
				_tmp100__length1 = _vala_array_length (properties);
				_tmp101_ = i;
				_tmp102_ = _tmp100_[_tmp101_];
				if (g_strcmp0 (_tmp102_, "DEVNAME") == 0) {
					gchar** _tmp103_;
					gint _tmp103__length1;
					gint _tmp104_;
					const gchar* _tmp105_;
					gboolean _tmp106_ = FALSE;
					_tmp103_ = properties;
					_tmp103__length1 = _vala_array_length (properties);
					_tmp104_ = i;
					_tmp105_ = _tmp103_[_tmp104_ + 1];
					_tmp106_ = g_str_has_prefix (_tmp105_, "/dev/");
					_tmp99_ = _tmp106_;
				} else {
					_tmp99_ = FALSE;
				}
				_tmp107_ = _tmp99_;
				if (_tmp107_) {
					const gchar* _tmp108_;
					gchar** _tmp109_;
					gint _tmp109__length1;
					gint _tmp110_;
					const gchar* _tmp111_;
					gchar* _tmp112_ = NULL;
					gchar* _tmp113_;
					gchar* _tmp114_;
					gchar* _tmp115_;
					gchar* _tmp116_;
					gchar* _tmp117_;
					gchar* _tmp118_;
					_tmp108_ = props;
					_tmp109_ = properties;
					_tmp109__length1 = _vala_array_length (properties);
					_tmp110_ = i;
					_tmp111_ = _tmp109_[_tmp110_ + 1];
					_tmp112_ = string_substring (_tmp111_, (glong) 5, (glong) (-1));
					_tmp113_ = _tmp112_;
					_tmp114_ = g_strconcat ("DEVNAME=", _tmp113_, NULL);
					_tmp115_ = _tmp114_;
					_tmp116_ = g_strconcat (_tmp115_, "\n", NULL);
					_tmp117_ = _tmp116_;
					_tmp118_ = g_strconcat (_tmp108_, _tmp117_, NULL);
					_g_free0 (props);
					props = _tmp118_;
					_g_free0 (_tmp117_);
					_g_free0 (_tmp115_);
					_g_free0 (_tmp113_);
				} else {
					const gchar* _tmp119_;
					gchar** _tmp120_;
					gint _tmp120__length1;
					gint _tmp121_;
					const gchar* _tmp122_;
					gchar* _tmp123_;
					gchar* _tmp124_;
					gchar** _tmp125_;
					gint _tmp125__length1;
					gint _tmp126_;
					const gchar* _tmp127_;
					gchar* _tmp128_;
					gchar* _tmp129_;
					gchar* _tmp130_;
					gchar* _tmp131_;
					gchar* _tmp132_;
					_tmp119_ = props;
					_tmp120_ = properties;
					_tmp120__length1 = _vala_array_length (properties);
					_tmp121_ = i;
					_tmp122_ = _tmp120_[_tmp121_];
					_tmp123_ = g_strconcat (_tmp122_, "=", NULL);
					_tmp124_ = _tmp123_;
					_tmp125_ = properties;
					_tmp125__length1 = _vala_array_length (properties);
					_tmp126_ = i;
					_tmp127_ = _tmp125_[_tmp126_ + 1];
					_tmp128_ = g_strconcat (_tmp124_, _tmp127_, NULL);
					_tmp129_ = _tmp128_;
					_tmp130_ = g_strconcat (_tmp129_, "\n", NULL);
					_tmp131_ = _tmp130_;
					_tmp132_ = g_strconcat (_tmp119_, _tmp131_, NULL);
					_g_free0 (props);
					props = _tmp132_;
					_g_free0 (_tmp131_);
					_g_free0 (_tmp129_);
					_g_free0 (_tmp124_);
				}
			}
		}
	}
	_tmp133_ = properties;
	_tmp133__length1 = _vala_array_length (properties);
	if ((_tmp133__length1 % 2) != 0) {
		gchar** _tmp134_;
		gint _tmp134__length1;
		gchar** _tmp135_;
		gint _tmp135__length1;
		const gchar* _tmp136_;
		_tmp134_ = properties;
		_tmp134__length1 = _vala_array_length (properties);
		_tmp135_ = properties;
		_tmp135__length1 = _vala_array_length (properties);
		_tmp136_ = _tmp134_[_tmp135__length1 - 1];
		g_warning ("umockdev.vala:270: add_devicev: Ignoring property key '%s' without val" \
"ue", _tmp136_);
	}
	_tmp137_ = dev_path;
	_tmp138_ = props;
	umockdev_testbed_set_attribute (self, _tmp137_, "uevent", _tmp138_);
	result = dev_path;
	_g_free0 (props);
	_g_free0 (dev_path_no_sys);
	_g_free0 (class_dir);
	_g_free0 (dev_dir);
	return result;
}


/**
     * umockdev_testbed_add_device: (skip)
     * @self: A #UMockdevTestbed.
     * @subsystem: The subsystem name, e. g. "usb"
     * @name: The device name; arbitrary, but needs to be unique within the testbed
     * @parent: (allow-none): device path of the parent device. Use %NULL for a
     *          top-level device.
     * @...: Arbitrarily many pairs of sysfs attributes (alternating names and
     *       values), terminated by %NULL, followed by arbitrarily many pairs of udev
     *       properties, terminated by another %NULL.
     *
     * Add a new device to the testbed. A Linux kernel device always has a
     * subsystem (such as "usb" or "pci"), and a device name. The test bed only
     * builds a very simple sysfs structure without nested namespaces, so it
     * requires device names to be unique. Some gudev client programs might make
     * assumptions about the name (e. g. a SCSI disk block device should be called
     * sdaN). A device also has an arbitrary number of sysfs attributes and udev
     * properties; usually you should specify them upon creation, but it is also
     * possible to change them later on with umockdev_testbed_set_attribute() and
     * umockdev_testbed_set_property().
     *
     * Example:
     *   |[
     *   umockdev_testbed_add_device (testbed, "usb", "dev1", NULL,
     *                              "idVendor", "0815", "idProduct", "AFFE", NULL,
     *                              "ID_MODEL", "KoolGadget", NULL);
     *   ]|
     *
     * Returns: The sysfs path for the newly created device. Free with g_free().
     */
static void _vala_array_add1 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void _vala_array_add2 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


gchar* umockdev_testbed_add_device (UMockdevTestbed* self, const gchar* subsystem, const gchar* name, const gchar* parent, ...) {
	gchar* result = NULL;
	gchar** _tmp0_ = NULL;
	gchar** attributes;
	gint attributes_length1;
	gint _attributes_size_;
	gchar** _tmp1_ = NULL;
	gchar** properties;
	gint properties_length1;
	gint _properties_size_;
	gint arg_set;
	va_list l = {0};
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	gchar** _tmp17_;
	gint _tmp17__length1;
	gchar** _tmp18_;
	gint _tmp18__length1;
	gchar* _tmp19_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (subsystem != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	attributes = _tmp0_;
	attributes_length1 = 0;
	_attributes_size_ = attributes_length1;
	_tmp1_ = g_new0 (gchar*, 0 + 1);
	properties = _tmp1_;
	properties_length1 = 0;
	_properties_size_ = properties_length1;
	arg_set = 0;
	va_start (l, parent);
	while (TRUE) {
		const gchar* _tmp2_ = NULL;
		gchar* _tmp3_;
		gchar* arg;
		const gchar* _tmp4_;
		gint _tmp7_;
		_tmp2_ = va_arg (l, gchar*);
		_tmp3_ = g_strdup (_tmp2_);
		arg = _tmp3_;
		_tmp4_ = arg;
		if (_tmp4_ == NULL) {
			gint _tmp5_;
			gint _tmp6_;
			_tmp5_ = arg_set;
			arg_set = _tmp5_ + 1;
			_tmp6_ = arg_set;
			if (_tmp6_ > 1) {
				_g_free0 (arg);
				break;
			} else {
				_g_free0 (arg);
				continue;
			}
		}
		_tmp7_ = arg_set;
		if (_tmp7_ == 0) {
			gchar** _tmp8_;
			gint _tmp8__length1;
			const gchar* _tmp9_;
			gchar* _tmp10_;
			_tmp8_ = attributes;
			_tmp8__length1 = attributes_length1;
			_tmp9_ = arg;
			_tmp10_ = g_strdup (_tmp9_);
			_vala_array_add1 (&attributes, &attributes_length1, &_attributes_size_, _tmp10_);
		} else {
			gchar** _tmp11_;
			gint _tmp11__length1;
			const gchar* _tmp12_;
			gchar* _tmp13_;
			_tmp11_ = properties;
			_tmp11__length1 = properties_length1;
			_tmp12_ = arg;
			_tmp13_ = g_strdup (_tmp12_);
			_vala_array_add2 (&properties, &properties_length1, &_properties_size_, _tmp13_);
		}
		_g_free0 (arg);
	}
	_tmp14_ = subsystem;
	_tmp15_ = name;
	_tmp16_ = parent;
	_tmp17_ = attributes;
	_tmp17__length1 = attributes_length1;
	_tmp18_ = properties;
	_tmp18__length1 = properties_length1;
	_tmp19_ = umockdev_testbed_add_devicev (self, _tmp14_, _tmp15_, _tmp16_, _tmp17_, _tmp18_);
	result = _tmp19_;
	va_end (l);
	properties = (_vala_array_free (properties, properties_length1, (GDestroyNotify) g_free), NULL);
	attributes = (_vala_array_free (attributes, attributes_length1, (GDestroyNotify) g_free), NULL);
	return result;
}


/**
     * umockdev_testbed_add_from_string:
     * @self: A #UMockdevTestbed.
     * @data: Description of the device(s) as generated with umockdev-record
     * @error: return location for a GError, or %NULL
     *
     * Add a set of devices to the testbed from a textual description. This reads
     * the format generated by the umockdev-record tool.
     *
     * Each paragraph defines one device. A line starts with a type tag (like 'E'),
     * followed by a colon, followed by either a value or a "key=value" assignment,
     * depending on the type tag. A device description must start with a 'P:' line.
     * Available type tags are:
     * <itemizedlist>
     *   <listitem><type>P:</type> <emphasis>path</emphasis>: device path in sysfs, starting with
     *             <filename>/devices/</filename>; must occur exactly once at the
     *             start of device definition</listitem>
     *   <listitem><type>E:</type> <emphasis>key=value</emphasis>: udev property
     *             </listitem>
     *   <listitem><type>A:</type> <emphasis>key=value</emphasis>: ASCII sysfs
     *             attribute, with backslash-style escaping of \ (\\) and newlines
     *             (\n)</listitem>
     *   <listitem><type>H:</type> <emphasis>key=value</emphasis>: binary sysfs
     *             attribute, with the value being written as continuous hex string
     *             (e. g. 0081FE0A..)</listitem>
     *   <listitem><type>N:</type> <emphasis>devname</emphasis>[=<emphasis>contents</emphasis>]:
     *             device node name (without the <filename>/dev/</filename>
     *             prefix); if <emphasis>contents</emphasis> is given (encoded in a
     *             continuous hex string), it creates a
     *             <filename>/dev/devname</filename> in the mock environment with
     *             the given contents, otherwise the created dev file will be
     *             empty.</listitem>
     *   <listitem><type>S:</type> <emphasis>linkname</emphasis>: device node
     *             symlink (without the <filename>/dev/</filename> prefix); ignored right
     *             now.</listitem>
     * </itemizedlist>
     *
     * Returns: %TRUE on success, %FALSE if the data is invalid and an error
     *          occurred.
     */
static inline GRegex* _thread_safe_regex_init (GRegex** re, const gchar * pattern, GRegexMatchFlags match_options) {
	if (g_once_init_enter ((volatile gsize*) re)) {
		GRegex* val = g_regex_new (pattern, match_options, 0, NULL);
		g_once_init_leave ((volatile gsize*) re, (gsize) val);
	}
	return *re;
}


static gpointer _g_regex_ref0 (gpointer self) {
	return self ? g_regex_ref (self) : NULL;
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	glong _tmp0_;
	gchar _tmp1_;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = index;
	_tmp1_ = ((gchar*) self)[_tmp0_];
	result = _tmp1_;
	return result;
}


gboolean umockdev_testbed_add_from_string (UMockdevTestbed* self, const gchar* data, GError** error) {
	gboolean result = FALSE;
	GRegex* _tmp0_;
	GRegex* _tmp2_;
	GRegex* _tmp4_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* cur_data;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (data != NULL, FALSE);
	_tmp0_ = self->priv->re_record_val;
	if (_tmp0_ == NULL) {
		GRegex* _tmp1_;
		_tmp1_ = _g_regex_ref0 (_thread_safe_regex_init (&_tmp_regex_0, "^([PSL]): (.*)(?>\\n|$)", 0));
		_g_regex_unref0 (self->priv->re_record_val);
		self->priv->re_record_val = _tmp1_;
	}
	_tmp2_ = self->priv->re_record_keyval;
	if (_tmp2_ == NULL) {
		GRegex* _tmp3_;
		_tmp3_ = _g_regex_ref0 (_thread_safe_regex_init (&_tmp_regex_1, "^([EAH]): ([a-zA-Z0-9_:+-]+)=(.*)(?>\\n|$)", 0));
		_g_regex_unref0 (self->priv->re_record_keyval);
		self->priv->re_record_keyval = _tmp3_;
	}
	_tmp4_ = self->priv->re_record_optval;
	if (_tmp4_ == NULL) {
		GRegex* _tmp5_;
		_tmp5_ = _g_regex_ref0 (_thread_safe_regex_init (&_tmp_regex_2, "^([N]): ([^=\\n]+)(?>=([0-9A-F]+))?(?>\\n|$)", 0));
		_g_regex_unref0 (self->priv->re_record_optval);
		self->priv->re_record_optval = _tmp5_;
	}
	_tmp6_ = data;
	_tmp7_ = g_strdup (_tmp6_);
	cur_data = _tmp7_;
	while (TRUE) {
		const gchar* _tmp8_;
		gchar _tmp9_ = '\0';
		const gchar* _tmp10_;
		gchar* _tmp11_ = NULL;
		gchar* _tmp12_;
		_tmp8_ = cur_data;
		_tmp9_ = string_get (_tmp8_, (glong) 0);
		if (!(_tmp9_ != '\0')) {
			break;
		}
		_tmp10_ = cur_data;
		_tmp11_ = umockdev_testbed_add_dev_from_string (self, _tmp10_, &_inner_error_);
		_tmp12_ = _tmp11_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == UMOCKDEV_ERROR) {
				g_propagate_error (error, _inner_error_);
				_g_free0 (cur_data);
				return FALSE;
			} else {
				_g_free0 (cur_data);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return FALSE;
			}
		}
		_g_free0 (cur_data);
		cur_data = _tmp12_;
	}
	result = TRUE;
	_g_free0 (cur_data);
	return result;
}


/**
     * umockdev_testbed_uevent:
     * @self: A #UMockdevTestbed.
     * @devpath: The full device path, as returned by #umockdev_testbed_add_device()
     * @action: "add", "remove", or "change"
     *
     * Generate an uevent for a device.
     */
void umockdev_testbed_uevent (UMockdevTestbed* self, const gchar* devpath, const gchar* action) {
	uevent_sender* _tmp0_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	uevent_sender* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (devpath != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->ev_sender;
	if (_tmp0_ == NULL) {
		const gchar* _tmp1_;
		uevent_sender* _tmp2_;
		uevent_sender* _tmp3_;
		g_debug ("umockdev.vala:400: umockdev_testbed_uevent: lazily initializing uevent" \
"_sender");
		_tmp1_ = self->priv->root_dir;
		_tmp2_ = uevent_sender_open (_tmp1_);
		_uevent_sender_close0 (self->priv->ev_sender);
		self->priv->ev_sender = _tmp2_;
		_tmp3_ = self->priv->ev_sender;
		_vala_assert (_tmp3_ != NULL, "this.ev_sender != null");
	}
	_tmp4_ = action;
	_tmp5_ = devpath;
	g_debug ("umockdev.vala:404: umockdev_testbed_uevent: sending uevent %s for devi" \
"ce %s", _tmp4_, _tmp5_);
	_tmp6_ = self->priv->ev_sender;
	_tmp7_ = devpath;
	_tmp8_ = action;
	uevent_sender_send (_tmp6_, _tmp7_, _tmp8_);
}


/**
     * umockdev_testbed_load_ioctl:
     * @self: A #UMockdevTestbed.
     * @dev: Device path (/dev/...) for which to load the ioctl record.
     * @recordfile: Path of the ioctl record file.
     * @error: return location for a GError, or %NULL
     *
     * Load an ioctl record file for a particular device into the testbed.
     * ioctl records can be created with umockdev-record --ioctl.
     * They can optionally be xz compressed to save space (but then are
     * required to have an .xz file name suffix).
     *
     * Returns: %TRUE on success, %FALSE if the data is invalid and an error
     *          occurred.
     */
gboolean umockdev_testbed_load_ioctl (UMockdevTestbed* self, const gchar* dev, const gchar* recordfile, GError** error) {
	gboolean result = FALSE;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* dest;
	gchar* contents = NULL;
	const gchar* _tmp3_;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	gint _tmp6_ = 0;
	const gchar* _tmp7_;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp24_;
	const gchar* _tmp25_;
	gboolean _tmp26_ = FALSE;
	gboolean _tmp27_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (dev != NULL, FALSE);
	g_return_val_if_fail (recordfile != NULL, FALSE);
	_tmp0_ = self->priv->root_dir;
	_tmp1_ = dev;
	_tmp2_ = g_build_filename (_tmp0_, "ioctl", _tmp1_, NULL);
	dest = _tmp2_;
	_tmp3_ = dest;
	_tmp4_ = g_path_get_dirname (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_mkdir_with_parents (_tmp5_, 0755);
	_vala_assert (_tmp6_ == 0, "DirUtils.create_with_parents(Path.get_dirname(dest), 0755) == 0");
	_g_free0 (_tmp5_);
	_tmp7_ = recordfile;
	_tmp8_ = g_str_has_suffix (_tmp7_, ".xz");
	if (_tmp8_) {
		{
			gint exit = 0;
			gchar* _tmp9_;
			gchar* _tmp10_;
			const gchar* _tmp11_;
			gchar* _tmp12_;
			gchar** _tmp13_ = NULL;
			gchar** _tmp14_;
			gint _tmp14__length1;
			gchar* _tmp15_ = NULL;
			gint _tmp16_ = 0;
			gint _tmp17_;
			_tmp9_ = g_strdup ("xz");
			_tmp10_ = g_strdup ("-cd");
			_tmp11_ = recordfile;
			_tmp12_ = g_strdup (_tmp11_);
			_tmp13_ = g_new0 (gchar*, 3 + 1);
			_tmp13_[0] = _tmp9_;
			_tmp13_[1] = _tmp10_;
			_tmp13_[2] = _tmp12_;
			_tmp14_ = _tmp13_;
			_tmp14__length1 = 3;
			g_spawn_sync (NULL, _tmp14_, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &_tmp15_, NULL, &_tmp16_, &_inner_error_);
			_g_free0 (contents);
			contents = _tmp15_;
			exit = _tmp16_;
			_tmp14_ = (_vala_array_free (_tmp14_, _tmp14__length1, (GDestroyNotify) g_free), NULL);
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == G_SPAWN_ERROR) {
					goto __catch3_g_spawn_error;
				}
				_g_free0 (contents);
				_g_free0 (dest);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return FALSE;
			}
			_tmp17_ = exit;
			_vala_assert (_tmp17_ == 0, "exit == 0");
		}
		goto __finally3;
		__catch3_g_spawn_error:
		{
			GError* e = NULL;
			const gchar* _tmp18_;
			const gchar* _tmp19_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp18_ = recordfile;
			_tmp19_ = e->message;
			g_error ("umockdev.vala:441: Cannot call xz to decompress %s: %s", _tmp18_, _tmp19_);
			_g_error_free0 (e);
		}
		__finally3:
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				g_propagate_error (error, _inner_error_);
				_g_free0 (contents);
				_g_free0 (dest);
				return FALSE;
			} else {
				_g_free0 (contents);
				_g_free0 (dest);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return FALSE;
			}
		}
	} else {
		const gchar* _tmp20_;
		gchar* _tmp21_ = NULL;
		gboolean _tmp22_ = FALSE;
		gboolean _tmp23_;
		_tmp20_ = recordfile;
		_tmp22_ = g_file_get_contents (_tmp20_, &_tmp21_, NULL, &_inner_error_);
		_g_free0 (contents);
		contents = _tmp21_;
		_tmp23_ = _tmp22_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				g_propagate_error (error, _inner_error_);
				_g_free0 (contents);
				_g_free0 (dest);
				return FALSE;
			} else {
				_g_free0 (contents);
				_g_free0 (dest);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return FALSE;
			}
		}
		_vala_assert (_tmp23_, "FileUtils.get_contents(recordfile, out contents)");
	}
	_tmp24_ = dest;
	_tmp25_ = contents;
	_tmp26_ = g_file_set_contents (_tmp24_, _tmp25_, (gssize) (-1), &_inner_error_);
	_tmp27_ = _tmp26_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == G_FILE_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (contents);
			_g_free0 (dest);
			return FALSE;
		} else {
			_g_free0 (contents);
			_g_free0 (dest);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return FALSE;
		}
	}
	result = _tmp27_;
	_g_free0 (contents);
	_g_free0 (dest);
	return result;
}


static void _vala_array_add3 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void _vala_array_add4 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void _vala_array_add5 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void _vala_array_add6 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void _vala_array_add7 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void _vala_array_add8 (gchar*** array, int* length, int* size, gchar* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static gchar* umockdev_testbed_add_dev_from_string (UMockdevTestbed* self, const gchar* data, GError** error) {
	gchar* result = NULL;
	gchar type = '\0';
	gchar* key = NULL;
	gchar* val = NULL;
	gchar* devpath;
	gchar* subsystem;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* cur_data;
	const gchar* _tmp2_;
	gchar _tmp3_ = '\0';
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gboolean _tmp7_ = FALSE;
	const gchar* _tmp8_;
	gboolean _tmp10_;
	const gchar* _tmp12_;
	gboolean _tmp13_ = FALSE;
	const gchar* _tmp16_;
	gchar** _tmp17_ = NULL;
	gchar** attrs;
	gint attrs_length1;
	gint _attrs_size_;
	gchar** _tmp18_ = NULL;
	gchar** binattrs;
	gint binattrs_length1;
	gint _binattrs_size_;
	gchar** _tmp19_ = NULL;
	gchar** props;
	gint props_length1;
	gint _props_size_;
	const gchar* _tmp81_;
	const gchar* _tmp84_;
	const gchar* _tmp85_;
	const gchar* _tmp86_;
	const gchar* _tmp87_;
	gchar* _tmp88_ = NULL;
	gchar* _tmp89_;
	gchar** _tmp90_;
	gint _tmp90__length1;
	gchar** _tmp91_;
	gint _tmp91__length1;
	gchar* _tmp92_ = NULL;
	gchar* _tmp93_;
	gchar* syspath;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (data != NULL, NULL);
	devpath = NULL;
	subsystem = NULL;
	_tmp0_ = data;
	_tmp1_ = g_strdup (_tmp0_);
	cur_data = _tmp1_;
	_tmp2_ = cur_data;
	_tmp6_ = umockdev_testbed_record_parse_line (self, _tmp2_, &_tmp3_, &_tmp4_, &_tmp5_);
	type = _tmp3_;
	_g_free0 (key);
	key = _tmp4_;
	_g_free0 (devpath);
	devpath = _tmp5_;
	_g_free0 (cur_data);
	cur_data = _tmp6_;
	_tmp8_ = cur_data;
	if (_tmp8_ == NULL) {
		_tmp7_ = TRUE;
	} else {
		gchar _tmp9_;
		_tmp9_ = type;
		_tmp7_ = _tmp9_ != 'P';
	}
	_tmp10_ = _tmp7_;
	if (_tmp10_) {
		GError* _tmp11_;
		_tmp11_ = g_error_new_literal (UMOCKDEV_ERROR, UMOCKDEV_ERROR_PARSE, "device descriptions must start with a \"P: /devices/path/...\" line");
		_inner_error_ = _tmp11_;
		if (_inner_error_->domain == UMOCKDEV_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (cur_data);
			_g_free0 (subsystem);
			_g_free0 (devpath);
			_g_free0 (val);
			_g_free0 (key);
			return NULL;
		} else {
			_g_free0 (cur_data);
			_g_free0 (subsystem);
			_g_free0 (devpath);
			_g_free0 (val);
			_g_free0 (key);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp12_ = devpath;
	_tmp13_ = g_str_has_prefix (_tmp12_, "/devices/");
	if (!_tmp13_) {
		const gchar* _tmp14_;
		GError* _tmp15_;
		_tmp14_ = devpath;
		_tmp15_ = g_error_new (UMOCKDEV_ERROR, UMOCKDEV_ERROR_VALUE, "invalid device path '%s': must start with /devices/", _tmp14_);
		_inner_error_ = _tmp15_;
		if (_inner_error_->domain == UMOCKDEV_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (cur_data);
			_g_free0 (subsystem);
			_g_free0 (devpath);
			_g_free0 (val);
			_g_free0 (key);
			return NULL;
		} else {
			_g_free0 (cur_data);
			_g_free0 (subsystem);
			_g_free0 (devpath);
			_g_free0 (val);
			_g_free0 (key);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp16_ = devpath;
	g_debug ("umockdev.vala:464: parsing device description for %s", _tmp16_);
	_tmp17_ = g_new0 (gchar*, 0 + 1);
	attrs = _tmp17_;
	attrs_length1 = 0;
	_attrs_size_ = attrs_length1;
	_tmp18_ = g_new0 (gchar*, 0 + 1);
	binattrs = _tmp18_;
	binattrs_length1 = 0;
	_binattrs_size_ = binattrs_length1;
	_tmp19_ = g_new0 (gchar*, 0 + 1);
	props = _tmp19_;
	props_length1 = 0;
	_props_size_ = props_length1;
	while (TRUE) {
		gboolean _tmp20_ = FALSE;
		const gchar* _tmp21_;
		gint _tmp22_;
		gint _tmp23_;
		gboolean _tmp26_;
		const gchar* _tmp27_;
		gchar _tmp28_ = '\0';
		gchar* _tmp29_ = NULL;
		gchar* _tmp30_ = NULL;
		gchar* _tmp31_ = NULL;
		const gchar* _tmp32_;
		gchar _tmp35_;
		_tmp21_ = cur_data;
		_tmp22_ = strlen (_tmp21_);
		_tmp23_ = _tmp22_;
		if (_tmp23_ > 0) {
			const gchar* _tmp24_;
			gchar _tmp25_ = '\0';
			_tmp24_ = cur_data;
			_tmp25_ = string_get (_tmp24_, (glong) 0);
			_tmp20_ = _tmp25_ != '\n';
		} else {
			_tmp20_ = FALSE;
		}
		_tmp26_ = _tmp20_;
		if (!_tmp26_) {
			break;
		}
		_tmp27_ = cur_data;
		_tmp31_ = umockdev_testbed_record_parse_line (self, _tmp27_, &_tmp28_, &_tmp29_, &_tmp30_);
		type = _tmp28_;
		_g_free0 (key);
		key = _tmp29_;
		_g_free0 (val);
		val = _tmp30_;
		_g_free0 (cur_data);
		cur_data = _tmp31_;
		_tmp32_ = cur_data;
		if (_tmp32_ == NULL) {
			const gchar* _tmp33_;
			GError* _tmp34_;
			_tmp33_ = devpath;
			_tmp34_ = g_error_new (UMOCKDEV_ERROR, UMOCKDEV_ERROR_PARSE, "malformed attribute or property line in description of device %s", _tmp33_);
			_inner_error_ = _tmp34_;
			if (_inner_error_->domain == UMOCKDEV_ERROR) {
				g_propagate_error (error, _inner_error_);
				props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
				binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
				attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (cur_data);
				_g_free0 (subsystem);
				_g_free0 (devpath);
				_g_free0 (val);
				_g_free0 (key);
				return NULL;
			} else {
				props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
				binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
				attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (cur_data);
				_g_free0 (subsystem);
				_g_free0 (devpath);
				_g_free0 (val);
				_g_free0 (key);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return NULL;
			}
		}
		_tmp35_ = type;
		switch (_tmp35_) {
			case 'H':
			{
				gchar** _tmp36_;
				gint _tmp36__length1;
				const gchar* _tmp37_;
				gchar* _tmp38_;
				gchar** _tmp39_;
				gint _tmp39__length1;
				const gchar* _tmp40_;
				gchar* _tmp41_;
				_tmp36_ = binattrs;
				_tmp36__length1 = binattrs_length1;
				_tmp37_ = key;
				_tmp38_ = g_strdup (_tmp37_);
				_vala_array_add3 (&binattrs, &binattrs_length1, &_binattrs_size_, _tmp38_);
				_tmp39_ = binattrs;
				_tmp39__length1 = binattrs_length1;
				_tmp40_ = val;
				_tmp41_ = g_strdup (_tmp40_);
				_vala_array_add4 (&binattrs, &binattrs_length1, &_binattrs_size_, _tmp41_);
				break;
			}
			case 'A':
			{
				gchar** _tmp42_;
				gint _tmp42__length1;
				const gchar* _tmp43_;
				gchar* _tmp44_;
				gchar** _tmp45_;
				gint _tmp45__length1;
				const gchar* _tmp46_;
				gchar* _tmp47_ = NULL;
				_tmp42_ = attrs;
				_tmp42__length1 = attrs_length1;
				_tmp43_ = key;
				_tmp44_ = g_strdup (_tmp43_);
				_vala_array_add5 (&attrs, &attrs_length1, &_attrs_size_, _tmp44_);
				_tmp45_ = attrs;
				_tmp45__length1 = attrs_length1;
				_tmp46_ = val;
				_tmp47_ = g_strcompress (_tmp46_);
				_vala_array_add6 (&attrs, &attrs_length1, &_attrs_size_, _tmp47_);
				break;
			}
			case 'E':
			{
				gchar** _tmp48_;
				gint _tmp48__length1;
				const gchar* _tmp49_;
				gchar* _tmp50_;
				gchar** _tmp51_;
				gint _tmp51__length1;
				const gchar* _tmp52_;
				gchar* _tmp53_;
				const gchar* _tmp54_;
				_tmp48_ = props;
				_tmp48__length1 = props_length1;
				_tmp49_ = key;
				_tmp50_ = g_strdup (_tmp49_);
				_vala_array_add7 (&props, &props_length1, &_props_size_, _tmp50_);
				_tmp51_ = props;
				_tmp51__length1 = props_length1;
				_tmp52_ = val;
				_tmp53_ = g_strdup (_tmp52_);
				_vala_array_add8 (&props, &props_length1, &_props_size_, _tmp53_);
				_tmp54_ = key;
				if (g_strcmp0 (_tmp54_, "SUBSYSTEM") == 0) {
					const gchar* _tmp55_;
					const gchar* _tmp58_;
					gchar* _tmp59_;
					_tmp55_ = subsystem;
					if (_tmp55_ != NULL) {
						const gchar* _tmp56_;
						GError* _tmp57_;
						_tmp56_ = devpath;
						_tmp57_ = g_error_new (UMOCKDEV_ERROR, UMOCKDEV_ERROR_VALUE, "duplicate SUBSYSTEM property in description of device %s", _tmp56_);
						_inner_error_ = _tmp57_;
						if (_inner_error_->domain == UMOCKDEV_ERROR) {
							g_propagate_error (error, _inner_error_);
							props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
							binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
							attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
							_g_free0 (cur_data);
							_g_free0 (subsystem);
							_g_free0 (devpath);
							_g_free0 (val);
							_g_free0 (key);
							return NULL;
						} else {
							props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
							binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
							attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
							_g_free0 (cur_data);
							_g_free0 (subsystem);
							_g_free0 (devpath);
							_g_free0 (val);
							_g_free0 (key);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
							g_clear_error (&_inner_error_);
							return NULL;
						}
					}
					_tmp58_ = val;
					_tmp59_ = g_strdup (_tmp58_);
					_g_free0 (subsystem);
					subsystem = _tmp59_;
				}
				break;
			}
			case 'P':
			{
				const gchar* _tmp60_;
				GError* _tmp61_;
				_tmp60_ = devpath;
				_tmp61_ = g_error_new (UMOCKDEV_ERROR, UMOCKDEV_ERROR_PARSE, "invalid P: line in description of device %s", _tmp60_);
				_inner_error_ = _tmp61_;
				if (_inner_error_->domain == UMOCKDEV_ERROR) {
					g_propagate_error (error, _inner_error_);
					props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
					binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
					attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (cur_data);
					_g_free0 (subsystem);
					_g_free0 (devpath);
					_g_free0 (val);
					_g_free0 (key);
					return NULL;
				} else {
					props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
					binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
					attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (cur_data);
					_g_free0 (subsystem);
					_g_free0 (devpath);
					_g_free0 (val);
					_g_free0 (key);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return NULL;
				}
			}
			case 'N':
			{
				const gchar* _tmp62_;
				const gchar* _tmp63_;
				gchar* _tmp64_ = NULL;
				gchar* path;
				const gchar* _tmp65_;
				gchar* _tmp66_ = NULL;
				gchar* _tmp67_;
				gint _tmp68_ = 0;
				guint8* _tmp69_ = NULL;
				guint8* contents;
				gint contents_length1;
				gint _contents_size_;
				const gchar* _tmp70_;
				_tmp62_ = self->priv->root_dir;
				_tmp63_ = key;
				_tmp64_ = g_build_filename (_tmp62_, "dev", _tmp63_, NULL);
				path = _tmp64_;
				_tmp65_ = path;
				_tmp66_ = g_path_get_dirname (_tmp65_);
				_tmp67_ = _tmp66_;
				_tmp68_ = g_mkdir_with_parents (_tmp67_, 0755);
				_vala_assert (_tmp68_ == 0, "DirUtils.create_with_parents(Path.get_dirname(path), 0755) == 0");
				_g_free0 (_tmp67_);
				_tmp69_ = g_new0 (guint8, 0);
				contents = _tmp69_;
				contents_length1 = 0;
				_contents_size_ = contents_length1;
				_tmp70_ = val;
				if (_tmp70_ != NULL) {
					const gchar* _tmp71_;
					gint _tmp72_ = 0;
					guint8* _tmp73_ = NULL;
					guint8* _tmp74_;
					gint _tmp74__length1;
					gint __tmp74__size_;
					_tmp71_ = val;
					_tmp73_ = umockdev_decode_hex (_tmp71_, &_tmp72_, &_inner_error_);
					_tmp74_ = _tmp73_;
					_tmp74__length1 = _tmp72_;
					__tmp74__size_ = _tmp74__length1;
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == UMOCKDEV_ERROR) {
							g_propagate_error (error, _inner_error_);
							contents = (g_free (contents), NULL);
							_g_free0 (path);
							props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
							binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
							attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
							_g_free0 (cur_data);
							_g_free0 (subsystem);
							_g_free0 (devpath);
							_g_free0 (val);
							_g_free0 (key);
							return NULL;
						} else {
							contents = (g_free (contents), NULL);
							_g_free0 (path);
							props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
							binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
							attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
							_g_free0 (cur_data);
							_g_free0 (subsystem);
							_g_free0 (devpath);
							_g_free0 (val);
							_g_free0 (key);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
							g_clear_error (&_inner_error_);
							return NULL;
						}
					}
					contents = (g_free (contents), NULL);
					contents = _tmp74_;
					contents_length1 = _tmp74__length1;
					_contents_size_ = contents_length1;
				}
				{
					const gchar* _tmp75_;
					guint8* _tmp76_;
					gint _tmp76__length1;
					_tmp75_ = path;
					_tmp76_ = contents;
					_tmp76__length1 = contents_length1;
					g_file_set_contents (_tmp75_, (const char*) _tmp76_, (size_t) _tmp76__length1, &_inner_error_);
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == G_FILE_ERROR) {
							goto __catch4_g_file_error;
						}
						contents = (g_free (contents), NULL);
						_g_free0 (path);
						props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
						binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
						attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (cur_data);
						_g_free0 (subsystem);
						_g_free0 (devpath);
						_g_free0 (val);
						_g_free0 (key);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
				}
				goto __finally4;
				__catch4_g_file_error:
				{
					GError* e = NULL;
					FILE* _tmp77_;
					const gchar* _tmp78_;
					e = _inner_error_;
					_inner_error_ = NULL;
					_tmp77_ = stderr;
					_tmp78_ = e->message;
					fprintf (_tmp77_, "Cannot create dev node file: %s\n", _tmp78_);
					abort ();
					_g_error_free0 (e);
				}
				__finally4:
				if (_inner_error_ != NULL) {
					if (_inner_error_->domain == UMOCKDEV_ERROR) {
						g_propagate_error (error, _inner_error_);
						contents = (g_free (contents), NULL);
						_g_free0 (path);
						props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
						binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
						attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (cur_data);
						_g_free0 (subsystem);
						_g_free0 (devpath);
						_g_free0 (val);
						_g_free0 (key);
						return NULL;
					} else {
						contents = (g_free (contents), NULL);
						_g_free0 (path);
						props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
						binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
						attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (cur_data);
						_g_free0 (subsystem);
						_g_free0 (devpath);
						_g_free0 (val);
						_g_free0 (key);
						g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
				}
				contents = (g_free (contents), NULL);
				_g_free0 (path);
				break;
			}
			case 'S':
			case 'L':
			{
				break;
			}
			default:
			{
				gchar _tmp79_;
				GError* _tmp80_;
				_tmp79_ = type;
				_tmp80_ = g_error_new (UMOCKDEV_ERROR, UMOCKDEV_ERROR_PARSE, "Unknown line type '%c'\n", _tmp79_);
				_inner_error_ = _tmp80_;
				if (_inner_error_->domain == UMOCKDEV_ERROR) {
					g_propagate_error (error, _inner_error_);
					props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
					binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
					attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (cur_data);
					_g_free0 (subsystem);
					_g_free0 (devpath);
					_g_free0 (val);
					_g_free0 (key);
					return NULL;
				} else {
					props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
					binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
					attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (cur_data);
					_g_free0 (subsystem);
					_g_free0 (devpath);
					_g_free0 (val);
					_g_free0 (key);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return NULL;
				}
			}
		}
	}
	_tmp81_ = subsystem;
	if (_tmp81_ == NULL) {
		const gchar* _tmp82_;
		GError* _tmp83_;
		_tmp82_ = devpath;
		_tmp83_ = g_error_new (UMOCKDEV_ERROR, UMOCKDEV_ERROR_VALUE, "missing SUBSYSTEM property in description of device %s", _tmp82_);
		_inner_error_ = _tmp83_;
		if (_inner_error_->domain == UMOCKDEV_ERROR) {
			g_propagate_error (error, _inner_error_);
			props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
			binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
			attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (cur_data);
			_g_free0 (subsystem);
			_g_free0 (devpath);
			_g_free0 (val);
			_g_free0 (key);
			return NULL;
		} else {
			props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
			binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
			attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (cur_data);
			_g_free0 (subsystem);
			_g_free0 (devpath);
			_g_free0 (val);
			_g_free0 (key);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp84_ = devpath;
	_tmp85_ = subsystem;
	g_debug ("umockdev.vala:530: creating device %s (subsystem %s)", _tmp84_, _tmp85_);
	_tmp86_ = subsystem;
	_tmp87_ = devpath;
	_tmp88_ = string_substring (_tmp87_, (glong) 9, (glong) (-1));
	_tmp89_ = _tmp88_;
	_tmp90_ = attrs;
	_tmp90__length1 = attrs_length1;
	_tmp91_ = props;
	_tmp91__length1 = props_length1;
	_tmp92_ = umockdev_testbed_add_devicev (self, _tmp86_, _tmp89_, NULL, _tmp90_, _tmp91_);
	_tmp93_ = _tmp92_;
	_g_free0 (_tmp89_);
	syspath = _tmp93_;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp94_;
			_tmp94_ = TRUE;
			while (TRUE) {
				gboolean _tmp95_;
				gint _tmp97_;
				gchar** _tmp98_;
				gint _tmp98__length1;
				gchar** _tmp99_;
				gint _tmp99__length1;
				gint _tmp100_;
				const gchar* _tmp101_;
				gint _tmp102_ = 0;
				guint8* _tmp103_ = NULL;
				guint8* _tmp104_;
				gint _tmp104__length1;
				gint __tmp104__size_;
				const gchar* _tmp105_;
				gchar** _tmp106_;
				gint _tmp106__length1;
				gint _tmp107_;
				const gchar* _tmp108_;
				guint8* _tmp109_;
				gint _tmp109__length1;
				_tmp95_ = _tmp94_;
				if (!_tmp95_) {
					gint _tmp96_;
					_tmp96_ = i;
					i = _tmp96_ + 2;
				}
				_tmp94_ = FALSE;
				_tmp97_ = i;
				_tmp98_ = binattrs;
				_tmp98__length1 = binattrs_length1;
				if (!(_tmp97_ < _tmp98__length1)) {
					break;
				}
				_tmp99_ = binattrs;
				_tmp99__length1 = binattrs_length1;
				_tmp100_ = i;
				_tmp101_ = _tmp99_[_tmp100_ + 1];
				_tmp103_ = umockdev_decode_hex (_tmp101_, &_tmp102_, &_inner_error_);
				_tmp104_ = _tmp103_;
				_tmp104__length1 = _tmp102_;
				__tmp104__size_ = _tmp104__length1;
				if (_inner_error_ != NULL) {
					if (_inner_error_->domain == UMOCKDEV_ERROR) {
						g_propagate_error (error, _inner_error_);
						_g_free0 (syspath);
						props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
						binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
						attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (cur_data);
						_g_free0 (subsystem);
						_g_free0 (devpath);
						_g_free0 (val);
						_g_free0 (key);
						return NULL;
					} else {
						_g_free0 (syspath);
						props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
						binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
						attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (cur_data);
						_g_free0 (subsystem);
						_g_free0 (devpath);
						_g_free0 (val);
						_g_free0 (key);
						g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
				}
				_tmp105_ = syspath;
				_tmp106_ = binattrs;
				_tmp106__length1 = binattrs_length1;
				_tmp107_ = i;
				_tmp108_ = _tmp106_[_tmp107_];
				_tmp109_ = _tmp104_;
				_tmp109__length1 = _tmp104__length1;
				umockdev_testbed_set_attribute_binary (self, _tmp105_, _tmp108_, _tmp109_, _tmp104__length1);
				_tmp109_ = (g_free (_tmp109_), NULL);
			}
		}
	}
	while (TRUE) {
		gboolean _tmp110_ = FALSE;
		const gchar* _tmp111_;
		gchar _tmp112_ = '\0';
		gboolean _tmp115_;
		const gchar* _tmp116_;
		const gchar* _tmp117_ = NULL;
		gchar* _tmp118_;
		_tmp111_ = cur_data;
		_tmp112_ = string_get (_tmp111_, (glong) 0);
		if (_tmp112_ != '\0') {
			const gchar* _tmp113_;
			gchar _tmp114_ = '\0';
			_tmp113_ = cur_data;
			_tmp114_ = string_get (_tmp113_, (glong) 0);
			_tmp110_ = _tmp114_ == '\n';
		} else {
			_tmp110_ = FALSE;
		}
		_tmp115_ = _tmp110_;
		if (!_tmp115_) {
			break;
		}
		_tmp116_ = cur_data;
		_tmp117_ = g_utf8_next_char (_tmp116_);
		_tmp118_ = g_strdup (_tmp117_);
		_g_free0 (cur_data);
		cur_data = _tmp118_;
	}
	result = cur_data;
	_g_free0 (syspath);
	props = (_vala_array_free (props, props_length1, (GDestroyNotify) g_free), NULL);
	binattrs = (_vala_array_free (binattrs, binattrs_length1, (GDestroyNotify) g_free), NULL);
	attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (subsystem);
	_g_free0 (devpath);
	_g_free0 (val);
	_g_free0 (key);
	return result;
}


/**
     * umockdev_testbed_record_parse_line:
     * @data: String to parse
     * @type: Pointer to a gchar which will get the line type (one of P, N,
     *        S, E, or H)
     * @key:  Pointer to a string which will get the key name; this will be
     *        set to %NULL for line types which do not have a key (P, N, S). You
     *        need to free this with g_free().
     * @value: Pointer to a string which will get the value. You need to
     *         free this with g_free().
     *
     * Parse one line from a device record file.
     *
     * Returns: Pointer to the next line start in @data, or %NULL if the first line
     * is not valid.
     */
static gchar* umockdev_testbed_record_parse_line (UMockdevTestbed* self, const gchar* data, gchar* type, gchar** key, gchar** val) {
	gchar _vala_type = '\0';
	gchar* _vala_key = NULL;
	gchar* _vala_val = NULL;
	gchar* result = NULL;
	GMatchInfo* match = NULL;
	GRegex* _tmp0_;
	const gchar* _tmp1_;
	GMatchInfo* _tmp2_ = NULL;
	gboolean _tmp3_ = FALSE;
	GMatchInfo* _tmp24_;
	gchar* _tmp25_ = NULL;
	gchar* type_str;
	const gchar* _tmp26_;
	const gchar* _tmp27_;
	gchar _tmp28_ = '\0';
	gint end_pos = 0;
	GMatchInfo* _tmp29_;
	gint _tmp30_ = 0;
	gboolean _tmp31_ = FALSE;
	const gchar* _tmp32_;
	gint _tmp33_;
	gchar* _tmp34_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (data != NULL, NULL);
	_tmp0_ = self->priv->re_record_val;
	_tmp1_ = data;
	_tmp3_ = g_regex_match (_tmp0_, _tmp1_, 0, &_tmp2_);
	_g_match_info_free0 (match);
	match = _tmp2_;
	if (_tmp3_) {
		GMatchInfo* _tmp4_;
		gchar* _tmp5_ = NULL;
		_g_free0 (_vala_key);
		_vala_key = NULL;
		_tmp4_ = match;
		_tmp5_ = g_match_info_fetch (_tmp4_, 2);
		_g_free0 (_vala_val);
		_vala_val = _tmp5_;
	} else {
		GRegex* _tmp6_;
		const gchar* _tmp7_;
		GMatchInfo* _tmp8_ = NULL;
		gboolean _tmp9_ = FALSE;
		_tmp6_ = self->priv->re_record_keyval;
		_tmp7_ = data;
		_tmp9_ = g_regex_match (_tmp6_, _tmp7_, 0, &_tmp8_);
		_g_match_info_free0 (match);
		match = _tmp8_;
		if (_tmp9_) {
			GMatchInfo* _tmp10_;
			gchar* _tmp11_ = NULL;
			GMatchInfo* _tmp12_;
			gchar* _tmp13_ = NULL;
			const gchar* _tmp14_;
			_tmp10_ = match;
			_tmp11_ = g_match_info_fetch (_tmp10_, 2);
			_g_free0 (_vala_key);
			_vala_key = _tmp11_;
			_tmp12_ = match;
			_tmp13_ = g_match_info_fetch (_tmp12_, 3);
			_g_free0 (_vala_val);
			_vala_val = _tmp13_;
			_tmp14_ = _vala_val;
			_vala_assert (_tmp14_ != NULL, "val != null");
		} else {
			GRegex* _tmp15_;
			const gchar* _tmp16_;
			GMatchInfo* _tmp17_ = NULL;
			gboolean _tmp18_ = FALSE;
			_tmp15_ = self->priv->re_record_optval;
			_tmp16_ = data;
			_tmp18_ = g_regex_match (_tmp15_, _tmp16_, 0, &_tmp17_);
			_g_match_info_free0 (match);
			match = _tmp17_;
			if (_tmp18_) {
				GMatchInfo* _tmp19_;
				gchar* _tmp20_ = NULL;
				GMatchInfo* _tmp21_;
				gchar* _tmp22_ = NULL;
				_tmp19_ = match;
				_tmp20_ = g_match_info_fetch (_tmp19_, 2);
				_g_free0 (_vala_key);
				_vala_key = _tmp20_;
				_tmp21_ = match;
				_tmp22_ = g_match_info_fetch (_tmp21_, 3);
				_g_free0 (_vala_val);
				_vala_val = _tmp22_;
			} else {
				const gchar* _tmp23_;
				_tmp23_ = data;
				g_debug ("umockdev.vala:577: record_parse_line: >%s< does not match anything, fa" \
"iling", _tmp23_);
				_vala_type = '\0';
				_g_free0 (_vala_key);
				_vala_key = NULL;
				_g_free0 (_vala_val);
				_vala_val = NULL;
				result = NULL;
				_g_match_info_free0 (match);
				if (type) {
					*type = _vala_type;
				}
				if (key) {
					*key = _vala_key;
				} else {
					_g_free0 (_vala_key);
				}
				if (val) {
					*val = _vala_val;
				} else {
					_g_free0 (_vala_val);
				}
				return result;
			}
		}
	}
	_tmp24_ = match;
	_tmp25_ = g_match_info_fetch (_tmp24_, 1);
	type_str = _tmp25_;
	_tmp26_ = type_str;
	_vala_assert (_tmp26_ != NULL, "type_str != null");
	_tmp27_ = type_str;
	_tmp28_ = string_get (_tmp27_, (glong) 0);
	_vala_type = _tmp28_;
	_tmp29_ = match;
	_tmp31_ = g_match_info_fetch_pos (_tmp29_, 0, NULL, &_tmp30_);
	end_pos = _tmp30_;
	_vala_assert (_tmp31_, "match.fetch_pos(0, null, out end_pos)");
	_tmp32_ = data;
	_tmp33_ = end_pos;
	_tmp34_ = string_substring (_tmp32_, (glong) _tmp33_, (glong) (-1));
	result = _tmp34_;
	_g_free0 (type_str);
	_g_match_info_free0 (match);
	if (type) {
		*type = _vala_type;
	}
	if (key) {
		*key = _vala_key;
	} else {
		_g_free0 (_vala_key);
	}
	if (val) {
		*val = _vala_val;
	} else {
		_g_free0 (_vala_val);
	}
	return result;
}


static void umockdev_testbed_class_init (UMockdevTestbedClass * klass) {
	umockdev_testbed_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (UMockdevTestbedPrivate));
	G_OBJECT_CLASS (klass)->finalize = umockdev_testbed_finalize;
}


static void umockdev_testbed_instance_init (UMockdevTestbed * self) {
	self->priv = UMOCKDEV_TESTBED_GET_PRIVATE (self);
	self->priv->ev_sender = NULL;
}


static void umockdev_testbed_finalize (GObject* obj) {
	UMockdevTestbed * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, UMOCKDEV_TYPE_TESTBED, UMockdevTestbed);
	_tmp0_ = self->priv->root_dir;
	g_debug ("umockdev.vala:65: Removing test bed %s", _tmp0_);
	_tmp1_ = self->priv->root_dir;
	umockdev_remove_dir (_tmp1_);
	g_unsetenv ("UMOCKDEV_DIR");
	_g_free0 (self->priv->root_dir);
	_g_free0 (self->priv->sys_dir);
	_g_regex_unref0 (self->priv->re_record_val);
	_g_regex_unref0 (self->priv->re_record_keyval);
	_g_regex_unref0 (self->priv->re_record_optval);
	_uevent_sender_close0 (self->priv->ev_sender);
	G_OBJECT_CLASS (umockdev_testbed_parent_class)->finalize (obj);
}


/**
 * SECTION:umockdev
 * @short_description: Build a test bed for testing software that handles Linux
 * hardware devices.
 *
 * The #UMockdevTestbed class builds a temporary sandbox for mock devices.
 * Right now this covers sysfs, uevents, basic support for /dev devices, and
 * recording/mocking usbdevfs (for PtP/MTP devices) and evdev (touch pads,
 * Wacom tablets, etc.) ioctls, but other aspects will be added in the future.
 * You can add a number of devices including arbitrary sysfs attributes and
 * udev properties, and then run your software in that test bed that is
 * independent of the actual hardware it is running on.  With this you can
 * simulate particular hardware in virtual environments up to some degree,
 * without needing any particular privileges or disturbing the whole system.
 *
 * You can either add devices by specifying individual device paths,
 * properties, and attributes, or use the umockdev-record tool to create a human
 * readable/editable record of a real device (and all its parents) and load
 * that into the testbed with umockdev_testbed_add_from_string().
 *
 * Instantiating a #UMockdevTestbed object creates a temporary directory with
 * an empty sysfs tree and sets the $UMOCKDEV_DIR environment variable so that
 * programs subsequently started under umockdev-wrapper will use the test bed
 * instead of the system's real sysfs.
 */
GType umockdev_testbed_get_type (void) {
	static volatile gsize umockdev_testbed_type_id__volatile = 0;
	if (g_once_init_enter (&umockdev_testbed_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (UMockdevTestbedClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) umockdev_testbed_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UMockdevTestbed), 0, (GInstanceInitFunc) umockdev_testbed_instance_init, NULL };
		GType umockdev_testbed_type_id;
		umockdev_testbed_type_id = g_type_register_static (G_TYPE_OBJECT, "UMockdevTestbed", &g_define_type_info, 0);
		g_once_init_leave (&umockdev_testbed_type_id__volatile, umockdev_testbed_type_id);
	}
	return umockdev_testbed_type_id__volatile;
}


void umockdev_remove_dir (const gchar* path) {
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp5_;
	const gchar* _tmp20_;
	gint _tmp21_ = 0;
	GError * _inner_error_ = NULL;
	g_return_if_fail (path != NULL);
	_tmp1_ = path;
	_tmp2_ = g_file_test (_tmp1_, G_FILE_TEST_IS_DIR);
	if (_tmp2_) {
		const gchar* _tmp3_;
		gboolean _tmp4_ = FALSE;
		_tmp3_ = path;
		_tmp4_ = g_file_test (_tmp3_, G_FILE_TEST_IS_SYMLINK);
		_tmp0_ = !_tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	_tmp5_ = _tmp0_;
	if (_tmp5_) {
		GDir* d = NULL;
		gchar* name = NULL;
		{
			const gchar* _tmp6_;
			GDir* _tmp7_ = NULL;
			GDir* _tmp8_;
			_tmp6_ = path;
			_tmp7_ = g_dir_open (_tmp6_, (guint) 0, &_inner_error_);
			_tmp8_ = _tmp7_;
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == G_FILE_ERROR) {
					goto __catch5_g_file_error;
				}
				_g_dir_close0 (d);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
			_g_dir_close0 (d);
			d = _tmp8_;
		}
		goto __finally5;
		__catch5_g_file_error:
		{
			GError* e = NULL;
			const gchar* _tmp9_;
			GError* _tmp10_;
			const gchar* _tmp11_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp9_ = path;
			_tmp10_ = e;
			_tmp11_ = _tmp10_->message;
			g_warning ("umockdev.vala:611: cannot open: %s: %s", _tmp9_, _tmp11_);
			_g_error_free0 (e);
			_g_dir_close0 (d);
			return;
		}
		__finally5:
		if (_inner_error_ != NULL) {
			_g_dir_close0 (d);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
		while (TRUE) {
			GDir* _tmp12_;
			const gchar* _tmp13_ = NULL;
			gchar* _tmp14_;
			const gchar* _tmp15_;
			const gchar* _tmp16_;
			const gchar* _tmp17_;
			gchar* _tmp18_ = NULL;
			gchar* _tmp19_;
			_tmp12_ = d;
			_tmp13_ = g_dir_read_name (_tmp12_);
			_tmp14_ = g_strdup (_tmp13_);
			_g_free0 (name);
			name = _tmp14_;
			_tmp15_ = name;
			if (!(_tmp15_ != NULL)) {
				break;
			}
			_tmp16_ = path;
			_tmp17_ = name;
			_tmp18_ = g_build_filename (_tmp16_, _tmp17_, NULL);
			_tmp19_ = _tmp18_;
			umockdev_remove_dir (_tmp19_);
			_g_free0 (_tmp19_);
		}
		_g_free0 (name);
		_g_dir_close0 (d);
	}
	_tmp20_ = path;
	_tmp21_ = g_remove (_tmp20_);
	if (_tmp21_ < 0) {
		const gchar* _tmp22_;
		gint _tmp23_;
		const gchar* _tmp24_ = NULL;
		_tmp22_ = path;
		_tmp23_ = errno;
		_tmp24_ = g_strerror (_tmp23_);
		g_warning ("umockdev.vala:621: cannot remove %s: %s", _tmp22_, _tmp24_);
	}
}


static gint string_index_of_char (const gchar* self, gunichar c, gint start_index) {
	gint result = 0;
	gint _tmp0_;
	gunichar _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _result_;
	gchar* _tmp3_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = start_index;
	_tmp1_ = c;
	_tmp2_ = g_utf8_strchr (((gchar*) self) + _tmp0_, (gssize) (-1), _tmp1_);
	_result_ = _tmp2_;
	_tmp3_ = _result_;
	if (_tmp3_ != NULL) {
		gchar* _tmp4_;
		_tmp4_ = _result_;
		result = (gint) (_tmp4_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}


gchar* umockdev_make_dotdots (const gchar* path) {
	gchar* result = NULL;
	gint offset;
	guint count;
	gchar* _tmp6_;
	gchar* dots;
	g_return_val_if_fail (path != NULL, NULL);
	offset = 0;
	count = (guint) 0;
	while (TRUE) {
		const gchar* _tmp0_;
		gint _tmp1_;
		gint _tmp2_ = 0;
		gint _tmp3_;
		guint _tmp4_;
		gint _tmp5_;
		_tmp0_ = path;
		_tmp1_ = offset;
		_tmp2_ = string_index_of_char (_tmp0_, (gunichar) '/', _tmp1_);
		offset = _tmp2_;
		_tmp3_ = offset;
		if (!(_tmp3_ >= 0)) {
			break;
		}
		_tmp4_ = count;
		count = _tmp4_ + 1;
		_tmp5_ = offset;
		offset = _tmp5_ + 1;
	}
	_tmp6_ = g_strdup ("");
	dots = _tmp6_;
	while (TRUE) {
		guint _tmp7_;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		guint _tmp10_;
		_tmp7_ = count;
		if (!(_tmp7_ > ((guint) 1))) {
			break;
		}
		_tmp8_ = dots;
		_tmp9_ = g_strconcat (_tmp8_, "../", NULL);
		_g_free0 (dots);
		dots = _tmp9_;
		_tmp10_ = count;
		count = _tmp10_ - 1;
	}
	result = dots;
	return result;
}


guint8 umockdev_hexdigit (gchar c) {
	guint8 result = 0U;
	gint _tmp0_ = 0;
	gchar _tmp1_;
	gint _tmp8_;
	_tmp1_ = c;
	if (_tmp1_ >= 'a') {
		gchar _tmp2_;
		_tmp2_ = c;
		_tmp0_ = (_tmp2_ - 'a') + 10;
	} else {
		gint _tmp3_ = 0;
		gchar _tmp4_;
		gint _tmp7_;
		_tmp4_ = c;
		if (_tmp4_ >= 'A') {
			gchar _tmp5_;
			_tmp5_ = c;
			_tmp3_ = (_tmp5_ - 'A') + 10;
		} else {
			gchar _tmp6_;
			_tmp6_ = c;
			_tmp3_ = (gint) (_tmp6_ - '0');
		}
		_tmp7_ = _tmp3_;
		_tmp0_ = _tmp7_;
	}
	_tmp8_ = _tmp0_;
	result = (guint8) _tmp8_;
	return result;
}


guint8* umockdev_decode_hex (const gchar* data, int* result_length1, GError** error) {
	guint8* result = NULL;
	const gchar* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	const gchar* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	gint len;
	gint _tmp8_;
	guint8* _tmp9_ = NULL;
	guint8* bin;
	gint bin_length1;
	gint _bin_size_;
	guint8* _tmp26_;
	gint _tmp26__length1;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (data != NULL, NULL);
	_tmp0_ = data;
	_tmp1_ = strlen (_tmp0_);
	_tmp2_ = _tmp1_;
	if ((_tmp2_ % 2) != 0) {
		const gchar* _tmp3_;
		GError* _tmp4_;
		_tmp3_ = data;
		_tmp4_ = g_error_new (UMOCKDEV_ERROR, UMOCKDEV_ERROR_PARSE, "malformed hexadecimal value: %s", _tmp3_);
		_inner_error_ = _tmp4_;
		if (_inner_error_->domain == UMOCKDEV_ERROR) {
			g_propagate_error (error, _inner_error_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp5_ = data;
	_tmp6_ = strlen (_tmp5_);
	_tmp7_ = _tmp6_;
	len = _tmp7_;
	_tmp8_ = len;
	_tmp9_ = g_new0 (guint8, _tmp8_ / 2);
	bin = _tmp9_;
	bin_length1 = _tmp8_ / 2;
	_bin_size_ = bin_length1;
	{
		guint i;
		i = (guint) 0;
		{
			gboolean _tmp10_;
			_tmp10_ = TRUE;
			while (TRUE) {
				gboolean _tmp11_;
				guint _tmp13_;
				guint8* _tmp14_;
				gint _tmp14__length1;
				guint8* _tmp15_;
				gint _tmp15__length1;
				guint _tmp16_;
				const gchar* _tmp17_;
				guint _tmp18_;
				gchar _tmp19_ = '\0';
				guint8 _tmp20_ = 0U;
				const gchar* _tmp21_;
				guint _tmp22_;
				gchar _tmp23_ = '\0';
				guint8 _tmp24_ = 0U;
				guint8 _tmp25_;
				_tmp11_ = _tmp10_;
				if (!_tmp11_) {
					guint _tmp12_;
					_tmp12_ = i;
					i = _tmp12_ + 1;
				}
				_tmp10_ = FALSE;
				_tmp13_ = i;
				_tmp14_ = bin;
				_tmp14__length1 = bin_length1;
				if (!(_tmp13_ < ((guint) _tmp14__length1))) {
					break;
				}
				_tmp15_ = bin;
				_tmp15__length1 = bin_length1;
				_tmp16_ = i;
				_tmp17_ = data;
				_tmp18_ = i;
				_tmp19_ = string_get (_tmp17_, (glong) (_tmp18_ * 2));
				_tmp20_ = umockdev_hexdigit (_tmp19_);
				_tmp21_ = data;
				_tmp22_ = i;
				_tmp23_ = string_get (_tmp21_, (glong) ((_tmp22_ * 2) + 1));
				_tmp24_ = umockdev_hexdigit (_tmp23_);
				_tmp15_[_tmp16_] = (guint8) ((_tmp20_ << 4) | _tmp24_);
				_tmp25_ = _tmp15_[_tmp16_];
			}
		}
	}
	_tmp26_ = bin;
	_tmp26__length1 = bin_length1;
	if (result_length1) {
		*result_length1 = _tmp26__length1;
	}
	result = _tmp26_;
	return result;
}


GQuark umockdev_error_quark (void) {
	return g_quark_from_static_string ("umockdev_error-quark");
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



