Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/branches/num64/runtime/c-libs/smlnj-time/timeofday.c
ViewVC logotype

View of /sml/branches/num64/runtime/c-libs/smlnj-time/timeofday.c

Parent Directory Parent Directory | Revision Log Revision Log

Revision 5229 - (download) (as text) (annotate)
Thu May 30 18:15:17 2019 UTC (4 months, 2 weeks ago) by jhr
File size: 1427 byte(s)
  porting runtime-system changes from trunk
/* timeofday.c
 * COPYRIGHT (c) 1994 by AT&T Bell Laboratories.

#  include "ml-osdep.h"
#  if defined(OPSYS_WIN32)
#    include <sys/types.h>
#    include <sys/timeb.h>
#  else
#    include <sys/time.h>
#  endif
#  error no timeofday mechanism
#include "ml-base.h"
#include "ml-values.h"
#include "ml-objects.h"
#include "cfun-proto-list.h"

/* _ml_Time_timeofday : unit -> (Int32.int * int)
 * Return the time of day.
 * NOTE: gettimeofday() is not POSIX (time() returns seconds, and is POSIX
 * and ISO C).
ml_val_t _ml_Time_timeofday (ml_state_t *msp, ml_val_t arg)
    int			c_sec, c_usec;
    ml_val_t		ml_sec, res;

#if defined(OPSYS_UNIX)
	struct timeval	t;

	gettimeofday (&t, NIL(struct timezone *));
	c_sec = t.tv_sec;
	c_usec = t.tv_usec;
#elif defined(OPSYS_WIN32)
  /* we could use Win32 GetSystemTime/SystemTimetoFileTime here,
   * but the conversion routines for 64-bit 100-ns values
   * (in the mapi dll) are non-Win32s
   * we'll use time routines from the C runtime for now.
	struct _timeb t;

	c_sec = t.time;
	c_usec = t.millitm*1000;
#error timeofday not defined for OS
#error no timeofday mechanism

    ml_sec = INT32_CtoML(msp, c_sec);
    REC_ALLOC2 (msp, res, ml_sec, INT_CtoML(c_usec));

    return res;

} /* end of _ml_Time_timeofday */

ViewVC Help
Powered by ViewVC 1.0.0