Home | History | Annotate | Line # | Download | only in lib
getsecs.c revision 1.1.1.1.18.1
      1 /*	$NetBSD: getsecs.c,v 1.1.1.1.18.1 1999/06/21 00:50:04 thorpej Exp $	*/
      2 
      3 /* extracted from netbsd:sys/arch/i386/netboot/misc.c */
      4 
      5 #include <sys/types.h>
      6 
      7 #include <lib/libsa/stand.h>
      8 
      9 #include "libi386.h"
     10 
     11 extern int biosgetrtc __P((u_long*));
     12 
     13 static inline u_long bcd2dec __P((u_long));
     14 
     15 static inline u_long
     16 bcd2dec(arg)
     17 	u_long arg;
     18 {
     19 	return ((arg >> 4) * 10 + (arg & 0x0f));
     20 }
     21 
     22 time_t
     23 getsecs() {
     24 	/*
     25 	 * Return the current time in seconds
     26 	 */
     27 
     28 	u_long t;
     29 	time_t sec;
     30 
     31 	if (biosgetrtc(&t))
     32 		panic("RTC invalid");
     33 
     34 	sec = bcd2dec(t & 0xff);
     35 	sec *= 60;
     36 	t >>= 8;
     37 	sec += bcd2dec(t & 0xff);
     38 	sec *= 60;
     39 	t >>= 8;
     40 	sec += bcd2dec(t & 0xff);
     41 
     42 	return (sec);
     43 }
     44