-#define NCALLS 90 /* number of system calls allowed */
+#define NCALLS 91 /* number of system calls allowed */
#define EXIT 1
#define FORK 2
#define FSYNC 87 /* to FS */
#define GETPRIORITY 88 /* to PM */
#define SETPRIORITY 89 /* to PM */
+#define GETTIMEOFDAY 90 /* to PM */
*/
#include <sys/time.h>
+#include <lib.h>
#include <time.h>
int gettimeofday(struct timeval *_RESTRICT tp, void *_RESTRICT tzp)
{
- if (time(&tp->tv_sec) == (time_t)-1)
- return -1;
- tp->tv_usec= 0;
+ message m;
- /* tzp has to be a nul pointer according to the standard. Otherwise
- * behavior is undefined. We can just ignore tzp.
- */
- return 0;
+ if (_syscall(MM, GETTIMEOFDAY, &m) < 0)
+ return -1;
+
+ tp->tv_sec = m.m2_l1;
+ tp->tv_usec = m.m2_l2;
+
+ return 0;
}
+
--- /dev/null
+.TH GETTIMEOFDAY 2 "July 6, 2005"
+.UC 4
+.SH NAME
+gettimeofday \- get date and time
+.SH SYNOPSIS
+.ft B
+.nf
+#include <sys/time.h>
+
+int gettimeofday(struct timeval *tp, struct timezone *tzp)
+.fi
+.ft R
+.SH DESCRIPTION
+.B Gettimeofday
+returns the time in seconds and microseconds since epoch in GMT
+(midnight, january 1st, 1970). The timezone argument tzp is expected
+to be NULL.
+.SH RETURNS
+0 on success, -1 on error. If -1 is returned, errno is set to indicate
+the error.
+.SH "SEE ALSO
+.BR ctime (3).
do_fsync, /* 87 = fsync */
no_sys, /* 88 = getpriority */
no_sys, /* 89 = setpriority */
+ no_sys, /* 90 = gettimeofday */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
_PROTOTYPE( int do_stime, (void) );
_PROTOTYPE( int do_time, (void) );
_PROTOTYPE( int do_times, (void) );
+_PROTOTYPE( int do_gettimeofday, (void) );
/* trace.c */
_PROTOTYPE( int do_trace, (void) );
no_sys, /* 87 = fsync */
do_getsetpriority, /* 88 = getpriority */
do_getsetpriority, /* 89 = setpriority */
+ do_gettimeofday, /* 90 = gettimeofday */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
return(OK);
}
+/*===========================================================================*
+ * do_gettimeofday *
+ *===========================================================================*/
+PUBLIC int do_gettimeofday(void)
+{
+ clock_t uptime;
+ int s;
+
+ if ( (s=sys_getuptime(&uptime)) != OK)
+ panic(__FILE__,"do_gettimeofday couldn't get uptime", s);
+
+ mp->mp_reply.m2_l1 = boottime + uptime/HZ;
+ mp->mp_reply.m2_l2 = (uptime%HZ)*1000000/HZ;
+
+ return(OK);
+}
+