static int do_btime_match(const iodef_criterion_value_t *cv, iodef_criterion_operator_t op, iodef_value_t *value) { int ret; time_t sec; struct tm lt, comp = *(struct tm *) cv->value; libiodef_bool_t need_full_compare = FALSE; if ( iodef_value_get_type(value) != IODEF_VALUE_TYPE_TIME ) return -1; sec = iodef_time_get_sec(iodef_value_get_time(value)); if ( ! gmtime_r(&sec, <) ) return libiodef_error_from_errno(errno); /* * Apply mask */ if ( comp.tm_sec < 0 ) lt.tm_sec = -1; else need_full_compare = TRUE; if ( comp.tm_min < 0 ) lt.tm_min = -1; else need_full_compare = TRUE; if ( comp.tm_mon < 0 ) lt.tm_mon = -1; else need_full_compare = TRUE; if ( comp.tm_hour < 0 ) lt.tm_hour = -1; else need_full_compare = TRUE; if ( comp.tm_mday < 0 ) lt.tm_mday = -1; else need_full_compare = TRUE; if ( comp.tm_year < 0 ) lt.tm_year = -1; else need_full_compare = TRUE; if ( comp.tm_wday < 0 ) lt.tm_wday = -1; if ( comp.tm_yday < 0 ) lt.tm_yday = -1; /* * The timegm() function ignores values supplied in the tm_wday * and tm_yday fields, match them manually: */ if ( comp.tm_wday >= 0 ) { ret = integer_compare(lt.tm_wday, comp.tm_wday, (need_full_compare) ? op | IODEF_CRITERION_OPERATOR_EQUAL : op); if ( ret != 1 ) return ret; } if ( comp.tm_yday >= 0 ) { ret = integer_compare(lt.tm_yday, comp.tm_yday, (need_full_compare) ? op | IODEF_CRITERION_OPERATOR_EQUAL : op); if ( ret != 1 ) return ret; } if ( ! need_full_compare ) return 1; return integer_compare(timegm(<), timegm(&comp), op); }
// MCA: BinaryGCD int integer_gcd(integer_t gcd, integer_t a, integer_t b) { integer_t u, v; size_t a0, b0, z; u = integer_create(0); v = gcd; a0 = integer_get_trailing_zeros(a); b0 = integer_get_trailing_zeros(b); z = MIN(a0, b0); VERIFY(integer_divide_power_of_two(u, a, a0)); VERIFY(integer_divide_power_of_two(v, b, b0)); VERIFY(integer_absolute_value(u, u)); VERIFY(integer_absolute_value(v, v)); while(!integers_are_equal(u, v)) { if(-1 == integer_compare(u, v)) { SWAP(u, v); } VERIFY(integer_subtract(u, u, v)); VERIFY(integer_divide_power_of_two(u, u, integer_get_trailing_zeros(u))); } VERIFY(integer_multiply_power_of_two(gcd, u, z)); if(u != gcd) { integer_destroy(u); } else { integer_destroy(v); } return 0; }