65816-llvm-mos/runtime/include/sys/time.h
Scott Duensing 3388f3c5a5 More updates
2026-06-03 20:46:31 -05:00

49 lines
1.5 KiB
C

// sys/time.h - POSIX gettimeofday() shim on the IIgs RTC.
//
// The IIgs Misc Tool ReadTimeHex (set $03, tool $0D) is the only
// hardware-visible wall clock; its resolution is one second. We
// expose it through the POSIX gettimeofday() surface so portable
// code that wants a coarse wall-time stamp (logging, srand,
// benchmark deltas in whole seconds) works unmodified.
//
// tv_sec is the same Unix epoch second count returned by time().
// tv_usec is always 0 (no sub-second hardware). The `tz` argument is
// accepted for source compatibility and silently ignored -- the IIgs
// has no timezone database.
//
// The signature mirrors the canonical POSIX one byte-for-byte so
// existing third-party code using `struct timeval` and gettimeofday()
// links cleanly against runtime/extras.o.
#ifndef _SYS_TIME_H
#define _SYS_TIME_H
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
// suseconds_t is an i32 on every common POSIX impl; we match that.
typedef long suseconds_t;
struct timeval {
time_t tv_sec; // seconds since the Unix epoch
suseconds_t tv_usec; // microseconds within the second (always 0 here)
};
struct timezone {
int tz_minuteswest; // minutes west of GMT (always 0)
int tz_dsttime; // DST correction (always 0)
};
// Returns 0 on success, -1 on failure (e.g. if the Tool Locator has
// not yet been initialised). `tz` is accepted for source compat and
// silently ignored. Calling with tv==NULL is a no-op success.
int gettimeofday(struct timeval *tv, void *tz);
#ifdef __cplusplus
}
#endif
#endif