require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_SYS_FD_SET_H_)) {
    eval 'sub _SYS_FD_SET_H_ () {1;}' unless defined(&_SYS_FD_SET_H_);
    require 'sys/cdefs.ph';
    require 'sys/featuretest.ph';
    require 'machine/int_types.ph';
    eval 'sub __NFDBITS () {(32);}' unless defined(&__NFDBITS);
    eval 'sub __NFDSHIFT () {(5);}' unless defined(&__NFDSHIFT);
    eval 'sub __NFDMASK () {( &__NFDBITS - 1);}' unless defined(&__NFDMASK);
    unless(defined(&FD_SETSIZE)) {
	eval 'sub FD_SETSIZE () {256;}' unless defined(&FD_SETSIZE);
    }
    eval 'sub __NFD_LEN {
        my($a) = @_;
	    eval q(((($a) + ( &__NFDBITS - 1)) /  &__NFDBITS));
    }' unless defined(&__NFD_LEN);
    eval 'sub __NFD_SIZE () { &__NFD_LEN( &FD_SETSIZE);}' unless defined(&__NFD_SIZE);
    eval 'sub __NFD_BYTES {
        my($a) = @_;
	    eval q(( &__NFD_LEN($a) * $sizeof{ &__fd_mask}));
    }' unless defined(&__NFD_BYTES);
    eval 'sub FD_SET {
        my($n, $p) = @_;
	    eval q((-> $fds_bits[($n) >>  &__NFDSHIFT] |= (1 << (($n) &  &__NFDMASK))));
    }' unless defined(&FD_SET);
    eval 'sub FD_CLR {
        my($n, $p) = @_;
	    eval q((-> $fds_bits[($n) >>  &__NFDSHIFT] &= ~(1 << (($n) &  &__NFDMASK))));
    }' unless defined(&FD_CLR);
    eval 'sub FD_ISSET {
        my($n, $p) = @_;
	    eval q((-> $fds_bits[($n) >>  &__NFDSHIFT] & (1 << (($n) &  &__NFDMASK))));
    }' unless defined(&FD_ISSET);
    if( &__GNUC_PREREQ__(2, 95)) {
	eval 'sub FD_ZERO {
	    my($p) = @_;
    	    eval q(( &void) &__builtin_memset(($p), 0, $sizeof{($p)}));
	}' unless defined(&FD_ZERO);
    } else {
	eval 'sub FD_ZERO {
	    my($p) = @_;
    	    eval q( &do {  &fd_set * &__fds = ($p); \'unsigned int __i\';  &for ( &__i = 0;  &__i <  &__NFD_SIZE;  &__i++)  ($__fds->{fds_bits[&__i]}) = 0; }  &while ( 0));
	}' unless defined(&FD_ZERO);
    }
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub fd_mask () { &__fd_mask;}' unless defined(&fd_mask);
	eval 'sub NFDBITS () { &__NFDBITS;}' unless defined(&NFDBITS);
	if( &__GNUC_PREREQ__(2, 95)) {
	    eval 'sub FD_COPY {
	        my($f, $t) = @_;
    		eval q(( &void) &__builtin_memcpy(($t), ($f), $sizeof{($f)}));
	    }' unless defined(&FD_COPY);
	} else {
	    eval 'sub FD_COPY {
	        my($f, $t) = @_;
    		eval q( &do {  &fd_set * &__f = ($f), * &__t = ($t); \'unsigned int __i\';  &for ( &__i = 0;  &__i <  &__NFD_SIZE;  &__i++)  ($__t->{fds_bits[&__i]}) =  ($__f->{fds_bits[&__i]}); }  &while ( 0));
	    }' unless defined(&FD_COPY);
	}
    }
}
1;
