require '_h2ph_pre.ph';

no warnings 'redefine';

require 'sys/fcntl.ph';
require 'sys/unistd.ph';
if(defined(&_KERNEL)) {
    require 'sys/queue.ph';
    eval 'sub DTYPE_VNODE () {1;}' unless defined(&DTYPE_VNODE);
    eval 'sub DTYPE_SOCKET () {2;}' unless defined(&DTYPE_SOCKET);
    eval 'sub DTYPE_PIPE () {3;}' unless defined(&DTYPE_PIPE);
    eval 'sub DTYPE_KQUEUE () {4;}' unless defined(&DTYPE_KQUEUE);
    eval 'sub DTYPE_CRYPTO () {5;}' unless defined(&DTYPE_CRYPTO);
    eval 'sub DTYPE_SYSTRACE () {6;}' unless defined(&DTYPE_SYSTRACE);
    eval 'sub FIF_WANTCLOSE () {0x1;}' unless defined(&FIF_WANTCLOSE);
    eval 'sub FIF_LARVAL () {0x2;}' unless defined(&FIF_LARVAL);
    eval 'sub FILE_IS_USABLE {
        my($fp) = @_;
	    eval q(((($fp)-> &f_iflags & ( &FIF_WANTCLOSE| &FIF_LARVAL)) == 0));
    }' unless defined(&FILE_IS_USABLE);
    eval 'sub FREF {
        my($fp) = @_;
	    eval q( &do { ($fp)-> &f_usecount++; }  &while (0));
    }' unless defined(&FREF);
    eval 'sub FRELE {
        my($fp) = @_;
	    eval q( &do { --($fp)-> &f_usecount;  &if ((($fp)-> &f_iflags &  &FIF_WANTCLOSE) != 0)  &wakeup(($fp)-> &f_usecount); }  &while (0));
    }' unless defined(&FRELE);
    eval 'sub FILE_SET_MATURE {
        my($fp) = @_;
	    eval q( &do { ($fp)-> &f_iflags &= ~ &FIF_LARVAL;  &FRELE($fp); }  &while (0));
    }' unless defined(&FILE_SET_MATURE);
}
1;
