require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_SYS_TIME_H_)) {
    eval 'sub _SYS_TIME_H_ () {1;}' unless defined(&_SYS_TIME_H_);
    require 'sys/cdefs.ph';
    require 'sys/types.ph';
    if((defined(&__XPG_VISIBLE) ? &__XPG_VISIBLE : 0) >= 420 && (defined(&__XPG_VISIBLE) ? &__XPG_VISIBLE : 0) < 600) {
	require 'sys/select.ph';
    }
    unless(defined(&_TIMESPEC_DECLARED)) {
	eval 'sub _TIMESPEC_DECLARED () {1;}' unless defined(&_TIMESPEC_DECLARED);
    }
    eval 'sub TIMEVAL_TO_TIMESPEC {
        my($tv, $ts) = @_;
	    eval q({ ($ts)-> &tv_sec = ($tv)-> &tv_sec; ($ts)-> &tv_nsec = ($tv)-> &tv_usec * 1000; });
    }' unless defined(&TIMEVAL_TO_TIMESPEC);
    eval 'sub TIMESPEC_TO_TIMEVAL {
        my($tv, $ts) = @_;
	    eval q({ ($tv)-> &tv_sec = ($ts)-> &tv_sec; ($tv)-> &tv_usec = ($ts)-> &tv_nsec / 1000; });
    }' unless defined(&TIMESPEC_TO_TIMEVAL);
    eval 'sub DST_NONE () {0;}' unless defined(&DST_NONE);
    eval 'sub DST_USA () {1;}' unless defined(&DST_USA);
    eval 'sub DST_AUST () {2;}' unless defined(&DST_AUST);
    eval 'sub DST_WET () {3;}' unless defined(&DST_WET);
    eval 'sub DST_MET () {4;}' unless defined(&DST_MET);
    eval 'sub DST_EET () {5;}' unless defined(&DST_EET);
    eval 'sub DST_CAN () {6;}' unless defined(&DST_CAN);
    eval 'sub timerclear {
        my($tvp) = @_;
	    eval q(($tvp)-> &tv_sec = ($tvp)-> &tv_usec = 0);
    }' unless defined(&timerclear);
    eval 'sub timerisset {
        my($tvp) = @_;
	    eval q((($tvp)-> &tv_sec || ($tvp)-> &tv_usec));
    }' unless defined(&timerisset);
    eval 'sub timercmp {
        my($tvp, $uvp, $cmp) = @_;
	    eval q(((($tvp)-> &tv_sec == ($uvp)-> &tv_sec) ? (($tvp)-> &tv_usec $cmp ($uvp)-> &tv_usec) : (($tvp)-> &tv_sec $cmp ($uvp)-> &tv_sec)));
    }' unless defined(&timercmp);
    eval 'sub timeradd {
        my($tvp, $uvp, $vvp) = @_;
	    eval q( &do { ($vvp)-> &tv_sec = ($tvp)-> &tv_sec + ($uvp)-> &tv_sec; ($vvp)-> &tv_usec = ($tvp)-> &tv_usec + ($uvp)-> &tv_usec;  &if (($vvp)-> &tv_usec >= 1000000) { ($vvp)-> &tv_sec++; ($vvp)-> &tv_usec -= 1000000; } }  &while (0));
    }' unless defined(&timeradd);
    eval 'sub timersub {
        my($tvp, $uvp, $vvp) = @_;
	    eval q( &do { ($vvp)-> &tv_sec = ($tvp)-> &tv_sec - ($uvp)-> &tv_sec; ($vvp)-> &tv_usec = ($tvp)-> &tv_usec - ($uvp)-> &tv_usec;  &if (($vvp)-> &tv_usec < 0) { ($vvp)-> &tv_sec--; ($vvp)-> &tv_usec += 1000000; } }  &while (0));
    }' unless defined(&timersub);
    eval 'sub timespecclear {
        my($tsp) = @_;
	    eval q(($tsp)-> &tv_sec = ($tsp)-> &tv_nsec = 0);
    }' unless defined(&timespecclear);
    eval 'sub timespecisset {
        my($tsp) = @_;
	    eval q((($tsp)-> &tv_sec || ($tsp)-> &tv_nsec));
    }' unless defined(&timespecisset);
    eval 'sub timespeccmp {
        my($tsp, $usp, $cmp) = @_;
	    eval q(((($tsp)-> &tv_sec == ($usp)-> &tv_sec) ? (($tsp)-> &tv_nsec $cmp ($usp)-> &tv_nsec) : (($tsp)-> &tv_sec $cmp ($usp)-> &tv_sec)));
    }' unless defined(&timespeccmp);
    eval 'sub timespecadd {
        my($tsp, $usp, $vsp) = @_;
	    eval q( &do { ($vsp)-> &tv_sec = ($tsp)-> &tv_sec + ($usp)-> &tv_sec; ($vsp)-> &tv_nsec = ($tsp)-> &tv_nsec + ($usp)-> &tv_nsec;  &if (($vsp)-> &tv_nsec >= 1000000000) { ($vsp)-> &tv_sec++; ($vsp)-> &tv_nsec -= 1000000000; } }  &while (0));
    }' unless defined(&timespecadd);
    eval 'sub timespecsub {
        my($tsp, $usp, $vsp) = @_;
	    eval q( &do { ($vsp)-> &tv_sec = ($tsp)-> &tv_sec - ($usp)-> &tv_sec; ($vsp)-> &tv_nsec = ($tsp)-> &tv_nsec - ($usp)-> &tv_nsec;  &if (($vsp)-> &tv_nsec < 0) { ($vsp)-> &tv_sec--; ($vsp)-> &tv_nsec += 1000000000; } }  &while (0));
    }' unless defined(&timespecsub);
    eval 'sub bintime_addx {
        my($bt,$x) = @_;
	    eval q({  &uint64_t  &u;  &u =  ($bt->{frac});  ($bt->{frac}) += $x;  &if ( &u >  ($bt->{frac}))  ($bt->{sec})++; });
    }' unless defined(&bintime_addx);
    eval 'sub bintime_add {
        my($bt,$bt2) = @_;
	    eval q({  &uint64_t  &u;  &u =  ($bt->{frac});  ($bt->{frac}) +=  ($bt2->{frac});  &if ( &u >  ($bt->{frac}))  ($bt->{sec})++;  ($bt->{sec}) +=  ($bt2->{sec}); });
    }' unless defined(&bintime_add);
    eval 'sub bintime_sub {
        my($bt,$bt2) = @_;
	    eval q({  &uint64_t  &u;  &u =  ($bt->{frac});  ($bt->{frac}) -=  ($bt2->{frac});  &if ( &u <  ($bt->{frac}))  ($bt->{sec})--;  ($bt->{sec}) -=  ($bt2->{sec}); });
    }' unless defined(&bintime_sub);
    eval 'sub timespec2bintime {
        my($ts,$bt) = @_;
	    eval q({  ($bt->{sec}) =  ($ts->{tv_sec});  ($bt->{frac}) = ( &uint64_t) ($ts->{tv_nsec}) * ( &uint64_t)18446744073; });
    }' unless defined(&timespec2bintime);
    eval 'sub bintime2timeval {
        my($bt,$tv) = @_;
	    eval q({  ($tv->{tv_sec}) =  ($bt->{sec});  ($tv->{tv_usec}) = ((( &uint64_t)1000000* ( &uint32_t)( ($bt->{frac}) >> 32)) >> 32); });
    }' unless defined(&bintime2timeval);
    eval 'sub timeval2bintime {
        my($tv,$bt) = @_;
	    eval q({  ($bt->{sec}) = ( &time_t) ($tv->{tv_sec});  ($bt->{frac}) = ( &uint64_t) ($tv->{tv_usec}) * ( &uint64_t)18446744073709; });
    }' unless defined(&timeval2bintime);
    eval 'sub ITIMER_REAL () {0;}' unless defined(&ITIMER_REAL);
    eval 'sub ITIMER_VIRTUAL () {1;}' unless defined(&ITIMER_VIRTUAL);
    eval 'sub ITIMER_PROF () {2;}' unless defined(&ITIMER_PROF);
    eval 'sub CLOCK_REALTIME () {0;}' unless defined(&CLOCK_REALTIME);
    eval 'sub CLOCK_VIRTUAL () {1;}' unless defined(&CLOCK_VIRTUAL);
    eval 'sub CLOCK_PROF () {2;}' unless defined(&CLOCK_PROF);
    eval 'sub CLOCK_MONOTONIC () {3;}' unless defined(&CLOCK_MONOTONIC);
    eval 'sub TIMER_RELTIME () {0x;}' unless defined(&TIMER_RELTIME);
    eval 'sub TIMER_ABSTIME () {0x1;}' unless defined(&TIMER_ABSTIME);
    if(defined( &_KERNEL) || defined( &_STANDALONE)) {
	eval 'sub FROMBCD {
	    my($x) = @_;
    	    eval q(((($x) >> 4) * 10+ (($x) & 0xf)));
	}' unless defined(&FROMBCD);
	eval 'sub TOBCD {
	    my($x) = @_;
    	    eval q(((($x) / 10* 16) + (($x) % 10)));
	}' unless defined(&TOBCD);
	eval 'sub SECDAY () {86400;}' unless defined(&SECDAY);
	eval 'sub SECYR () {( &SECDAY * 365);}' unless defined(&SECYR);
	eval 'sub POSIX_BASE_YEAR () {1970;}' unless defined(&POSIX_BASE_YEAR);
    } else {
	require 'time.ph';
	if((defined(&__BSD_VISIBLE) ? &__BSD_VISIBLE : 0) || (defined(&__XPG_VISIBLE) ? &__XPG_VISIBLE : 0)) {
	    if((defined(&__BSD_VISIBLE) ? &__BSD_VISIBLE : 0)) {
	    }
	    if((defined(&__XPG_VISIBLE) ? &__XPG_VISIBLE : 0)) {
	    }
	}
    }
}
1;
