/* Minimal main program -- everything is loaded from the library */

#include "Python.h"

#ifdef __FreeBSD__
# include <floatingpoint.h>
#endif
#ifdef __sgi
# include <sys/fpu.h>
#endif

#ifdef __linux__
#include <linux/prctl.h>
#include <sys/prctl.h>
#ifndef PR_SET_NAME
#define PR_SET_NAME 15
#endif
#endif

int
main(int argc, char **argv)
{
	if (getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION")) {
		printf("GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n");
		return 0;
	}

	/* 754 requires that FP exceptions run in "no stop" mode by default,
	 * and until C vendors implement C99's ways to control FP exceptions,
	 * Python requires non-stop mode.  Alas, some platforms enable FP
	 * exceptions by default.  Here we disable them.
	 */
#ifdef __FreeBSD__
	fp_except_t m;

	m = fpgetmask();
	fpsetmask(m & ~FP_X_OFL);
#endif
#ifdef __sgi
	unsigned int m;

	m = get_fpc_csr();
	set_fpc_csr(m & ~FPCSR_FLUSH_ZERO);
#endif

#ifdef __linux__
	char *process_name = getenv("GENTOO_PYTHON_PROCESS_NAME");
#ifdef HAVE_UNSETENV
	unsetenv("GENTOO_PYTHON_PROCESS_NAME");
#endif
	if (process_name != NULL && *process_name != '\0')
		prctl(PR_SET_NAME, process_name);
#endif

	return Py_Main(argc, argv);
}
