require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_SYS_SELECT_H_)) {
    eval 'sub _SYS_SELECT_H_ () {1;}' unless defined(&_SYS_SELECT_H_);
    require 'sys/cdefs.ph';
    require 'sys/time.ph';
    unless(defined(&FD_SETSIZE)) {
	eval 'sub FD_SETSIZE () {1024;}' unless defined(&FD_SETSIZE);
    }
    eval 'sub __NBBY () {8;}' unless defined(&__NBBY);
    eval 'sub __NFDBITS () {(($sizeof{ &__fd_mask} *  &__NBBY));}' unless defined(&__NFDBITS);
    eval 'sub __howmany {
        my($x, $y) = @_;
	    eval q(((($x) + (($y) - 1)) / ($y)));
    }' unless defined(&__howmany);
    eval 'sub FD_SET {
        my($n, $p) = @_;
	    eval q((($p)-> $fds_bits[($n) /  &__NFDBITS] |= (1<< (($n) %  &__NFDBITS))));
    }' unless defined(&FD_SET);
    eval 'sub FD_CLR {
        my($n, $p) = @_;
	    eval q((($p)-> $fds_bits[($n) /  &__NFDBITS] &= ~(1<< (($n) %  &__NFDBITS))));
    }' unless defined(&FD_CLR);
    eval 'sub FD_ISSET {
        my($n, $p) = @_;
	    eval q((($p)-> $fds_bits[($n) /  &__NFDBITS] & (1<< (($n) %  &__NFDBITS))));
    }' unless defined(&FD_ISSET);
    if(defined(&_KERNEL)) {
	eval 'sub FD_COPY {
	    my($f, $t) = @_;
    	    eval q( &bcopy($f, $t, $sizeof{($f)}));
	}' unless defined(&FD_COPY);
	eval 'sub FD_ZERO {
	    my($p) = @_;
    	    eval q( &bzero($p, $sizeof{($p)}));
	}' unless defined(&FD_ZERO);
    } else {
	eval 'sub FD_COPY {
	    my($f, $t) = @_;
    	    eval q( &memcpy($t, $f, $sizeof{($f)}));
	}' unless defined(&FD_COPY);
	eval 'sub FD_ZERO {
	    my($p) = @_;
    	    eval q( &memset($p, 0, $sizeof{($p)}));
	}' unless defined(&FD_ZERO);
    }
    if((defined(&__BSD_VISIBLE) ? &__BSD_VISIBLE : 0)) {
	eval 'sub NBBY () { &__NBBY;}' unless defined(&NBBY);
	eval 'sub fd_mask () { &__fd_mask;}' unless defined(&fd_mask);
	eval 'sub NFDBITS () { &__NFDBITS;}' unless defined(&NFDBITS);
	unless(defined(&howmany)) {
	    eval 'sub howmany {
	        my($x, $y) = @_;
    		eval q( &__howmany($x, $y));
	    }' unless defined(&howmany);
	}
    }
    unless(defined(&_KERNEL)) {
	unless(defined(&_SELECT_DEFINED_)) {
	    eval 'sub _SELECT_DEFINED_ () {1;}' unless defined(&_SELECT_DEFINED_);
	}
    }
}
1;
