- uint64_t offset_cycles_ns;
-
- /* Initialize nanosecond timestamp to clock's offset in seconds */
- if (clock_class->offset_seconds <= (INT64_MIN / INT64_C(1000000000) - 1) ||
- clock_class->offset_seconds >= (INT64_MAX / INT64_C(1000000000)) - 1) {
- /*
- * Overflow: offset in seconds converted to nanoseconds
- * is outside the int64_t range. We also subtract 1 here
- * to leave "space" for the offset in cycles converted
- * to nanoseconds (which is always less than 1 second by
- * contract).
- */
- clock_class->base_offset.overflows = true;
- goto end;
- }
-
- /* Offset (seconds) to nanoseconds */
- clock_class->base_offset.value_ns = clock_class->offset_seconds *
- INT64_C(1000000000);
-
- /* Add offset in cycles */
- BT_ASSERT(clock_class->offset_cycles < clock_class->frequency);
- offset_cycles_ns = bt_util_ns_from_value(clock_class->frequency,
- clock_class->offset_cycles);
- BT_ASSERT(offset_cycles_ns < 1000000000);
- clock_class->base_offset.value_ns += (int64_t) offset_cycles_ns;
- clock_class->base_offset.overflows = false;
-
-end:
- return;
+ clock_class->base_offset.overflows = bt_util_get_base_offset_ns(
+ clock_class->offset_seconds, clock_class->offset_cycles,
+ clock_class->frequency, &clock_class->base_offset.value_ns);