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

/*
* Copyright (c) 2009-2013 Yorba Foundation
*
* This program 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#include <glib.h>
#include <unistd.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>
#include "io.elementary.photos.h"

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

VALA_EXTERN gint number_of_processors (void);
VALA_EXTERN GFile* get_sys_install_dir (GFile* exec_dir);
VALA_EXTERN gint posix_wexitstatus (gint status);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gint
number_of_processors (void)
{
	gint n = 0;
	gint _tmp0_ = 0;
	gint result;
	n = (gint) sysconf (_SC_NPROCESSORS_ONLN);
	if (n <= 0) {
		_tmp0_ = 1;
	} else {
		_tmp0_ = n;
	}
	result = _tmp0_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

GFile*
get_sys_install_dir (GFile* exec_dir)
{
	GFile* exec_dir1 = NULL;
	GFile* _tmp0_;
	GFile* prefix_dir = NULL;
	GFile* _tmp12_;
	GFile* _tmp13_ = NULL;
	GFile* _tmp14_;
	GFile* _tmp15_;
	GFile* _tmp17_;
	GError* _inner_error0_ = NULL;
	GFile* result;
	g_return_val_if_fail (exec_dir != NULL, NULL);
	_tmp0_ = _g_object_ref0 (exec_dir);
	exec_dir1 = _tmp0_;
	{
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_ = NULL;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		GFile* _tmp11_;
		_tmp2_ = g_file_get_path (exec_dir);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_file_read_link (_tmp3_, &_inner_error0_);
		_tmp5_ = _tmp4_;
		_g_free0 (_tmp3_);
		_tmp1_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_FILE_ERROR) {
				goto __catch0_g_file_error;
			}
			_g_object_unref0 (exec_dir1);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp7_ = g_strconcat ("/", _tmp1_, NULL);
		_tmp8_ = _tmp7_;
		_tmp9_ = g_file_read_link (_tmp8_, &_inner_error0_);
		_tmp10_ = _tmp9_;
		_g_free0 (_tmp8_);
		_tmp6_ = _tmp10_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (_tmp1_);
			if (_inner_error0_->domain == G_FILE_ERROR) {
				goto __catch0_g_file_error;
			}
			_g_object_unref0 (exec_dir1);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp11_ = g_file_new_for_path (_tmp6_);
		_g_object_unref0 (exec_dir1);
		exec_dir1 = _tmp11_;
		_g_free0 (_tmp6_);
		_g_free0 (_tmp1_);
	}
	goto __finally0;
	__catch0_g_file_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (exec_dir1);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	_tmp12_ = g_file_new_for_path (RESOURCES_PREFIX);
	prefix_dir = _tmp12_;
	_tmp14_ = exec_dir1;
	_tmp15_ = prefix_dir;
	if (g_file_has_prefix (_tmp14_, _tmp15_)) {
		GFile* _tmp16_;
		_tmp16_ = prefix_dir;
		_tmp13_ = _tmp16_;
	} else {
		_tmp13_ = NULL;
	}
	_tmp17_ = _g_object_ref0 (_tmp13_);
	result = _tmp17_;
	_g_object_unref0 (prefix_dir);
	_g_object_unref0 (exec_dir1);
	return result;
}

gint
posix_wexitstatus (gint status)
{
	gint result;
	result = (status & 0xff00) >> 8;
	return result;
}

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

