Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / arch / i386-darwin / dos / datestamp.c
blobf24763032b5ef4914b1dd2fa12e71b7d8f31a800
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Unix-based implementation of DateStamp()
6 Lang: english
7 */
8 #include <aros/system.h>
9 #include <exec/types.h>
10 #include <aros/libcall.h>
11 #include <aros/host-conf.h>
13 #define timeval sys_timeval
14 #include <sys/time.h>
15 #include <stdlib.h>
16 #undef timeval
17 #include "dos_intern.h"
19 #define SECONDS_PER_DAY (60UL * 60 * 24)
20 #define SECONDS_PER_MINUTE (60UL)
21 #define uSEC_PER_SEC (1000000UL)
22 #define TICKS_PER_SEC (50UL)
23 #define uSEC_PER_TICK (uSEC_PER_SEC / TICKS_PER_SEC)
24 #define AMIGA_UNIX_OFFSET (2922UL) /* Days between 1.1.78 (Amiga) and 1.1.70 (Unix) */
26 AROS_LH1(struct DateStamp *, DateStamp,
27 AROS_LHA(struct DateStamp *, date, D1),
28 struct DosLibrary *, DOSBase, 32, Dos)
30 AROS_LIBFUNC_INIT
32 struct sys_timeval stv;
33 gettimeofday (&stv, NULL);
35 date->ds_Days = stv.tv_sec / SECONDS_PER_DAY - AMIGA_UNIX_OFFSET;
36 stv.tv_sec %= SECONDS_PER_DAY;
37 date->ds_Minute = stv.tv_sec / SECONDS_PER_MINUTE;
38 stv.tv_sec %= SECONDS_PER_MINUTE;
39 date->ds_Tick = (stv.tv_usec + stv.tv_sec * uSEC_PER_SEC) /
40 uSEC_PER_TICK;
42 return date;
43 AROS_LIBFUNC_EXIT
44 } /* DateStamp */