TYPEMAP

INPUT
T_FILE_DESCRIPTOR
	{
		PerlIO* ${var}_io = IoIFP(sv_2io($arg));
		$var = ${var}_io ? PerlIO_fileno(${var}_io) : -1;
	}
T_DIR_DESCRIPTOR
	if (SvOK($arg)) {
		IO* ${var}_io = sv_2io($arg);
		if (IoDIRP(${var}_io)) {
			$var = dirfd(IoDIRP(${var}_io));
		} else
			$var = -1;
	} else
		$var = AT_FDCWD;
T_OPAQUEOBJ
    {
		SV * sv = $arg;
		if (SvROK(sv) && SvPOK(SvRV(sv)) && SvCUR(SvRV(sv)) == sizeof(*$var))
			$var = ($type)SvPV_nolen(SvRV(sv));
		else
			croak(\"%s: %s is not of type %s\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\", \"$ntype\");
    }

T_OPAQUEOBJ_MAYBE
	{
		SV * sv = $arg;
		if (SvOK(sv)) {
			if (SvROK(sv) && SvPOK(SvRV(sv)) && SvCUR(SvRV(sv)) == sizeof(*$var))
				$var = ($type)SvPV_nolen(SvRV(sv));
			else
				croak(\"%s: %s is not of type %s\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\", \"$ntype\");
		} else
			$var = NULL;
	}


OUTPUT
T_OPAQUEOBJ
	{
		sv_usepvn(newSVrv($arg, \"$ntype\"), (char*)$var, sizeof(*$var));
		SvREADONLY_on(SvRV($arg));
	}

T_OPAQUEOBJ_MAYBE
	if (SvOK($var)) {
		sv_usepvn(newSVrv($arg, \"$ntype\"), (char*)$var, sizeof(*$var));
		SvREADONLY_on(SvRV($arg));
	}

