require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_SYS_DIRENT_H_)) {
    eval 'sub _SYS_DIRENT_H_ () {1;}' unless defined(&_SYS_DIRENT_H_);
    require 'sys/cdefs.ph';
    require 'sys/featuretest.ph';
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub MAXNAMLEN () {511;}' unless defined(&MAXNAMLEN);
    } else {
    }
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub DT_UNKNOWN () {0;}' unless defined(&DT_UNKNOWN);
	eval 'sub DT_FIFO () {1;}' unless defined(&DT_FIFO);
	eval 'sub DT_CHR () {2;}' unless defined(&DT_CHR);
	eval 'sub DT_DIR () {4;}' unless defined(&DT_DIR);
	eval 'sub DT_BLK () {6;}' unless defined(&DT_BLK);
	eval 'sub DT_REG () {8;}' unless defined(&DT_REG);
	eval 'sub DT_LNK () {10;}' unless defined(&DT_LNK);
	eval 'sub DT_SOCK () {12;}' unless defined(&DT_SOCK);
	eval 'sub DT_WHT () {14;}' unless defined(&DT_WHT);
	eval 'sub _DIRENT_ALIGN {
	    my($dp) = @_;
    	    eval q(($sizeof{($dp)-> &d_fileno} - 1));
	}' unless defined(&_DIRENT_ALIGN);
	if( &__GNUC_PREREQ__(4, 0)) {
	    eval 'sub _DIRENT_NAMEOFF {
	        my($dp) = @_;
    		eval q( &__builtin_offsetof( &__typeof__(*($dp)),  &d_name));
	    }' unless defined(&_DIRENT_NAMEOFF);
	} else {
	    eval 'sub _DIRENT_NAMEOFF {
	        my($dp) = @_;
    		eval q((&-> &d_name - ( &void *)$dp));
	    }' unless defined(&_DIRENT_NAMEOFF);
	}
	eval 'sub _DIRENT_RECLEN {
	    my($dp, $namlen) = @_;
    	    eval q((( &_DIRENT_NAMEOFF($dp) + ($namlen) + 1+  &_DIRENT_ALIGN($dp)) & ~ &_DIRENT_ALIGN($dp)));
	}' unless defined(&_DIRENT_RECLEN);
	eval 'sub _DIRENT_SIZE {
	    my($dp) = @_;
    	    eval q( &_DIRENT_RECLEN($dp, ($dp)-> &d_namlen));
	}' unless defined(&_DIRENT_SIZE);
	eval 'sub _DIRENT_NEXT {
	    my($dp) = @_;
    	    eval q((( &void *)(( &void *)($dp) + ($dp)-> &d_reclen)));
	}' unless defined(&_DIRENT_NEXT);
	eval 'sub _DIRENT_MINSIZE {
	    my($dp) = @_;
    	    eval q( &_DIRENT_RECLEN($dp, 0));
	}' unless defined(&_DIRENT_MINSIZE);
	eval 'sub IFTODT {
	    my($mode) = @_;
    	    eval q(((($mode) & 0170000) >> 12));
	}' unless defined(&IFTODT);
	eval 'sub DTTOIF {
	    my($dirtype) = @_;
    	    eval q((($dirtype) << 12));
	}' unless defined(&DTTOIF);
    }
}
1;
