aboutsummaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'time.c')
-rwxr-xr-x[-rw-r--r--]time.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/time.c b/time.c
index 575518e..7789e92 100644..100755
--- a/time.c
+++ b/time.c
@@ -104,7 +104,6 @@
#ifdef __OpenBSD__
# include <sys/types.h>
# include <sys/time.h>
-# include <sys/timeb.h>
# define USE_GETTIMEOFDAY
#endif
#ifdef __TURBOC__
@@ -308,18 +307,40 @@ SCM your_time()
#else /* LACK_FTIME */
# ifdef USE_GETTIMEOFDAY
int scm_ftime(time_buffer)
- struct timeb *time_buffer;
+ struct timeval *time_buffer;
{
- struct timezone t_z; struct timeval t_v;
- if (gettimeofday(&t_v, &t_z) < 0) return -1;
- time_buffer->timezone = t_z.tz_minuteswest;
- time_buffer->dstflag = t_z.tz_dsttime;
- time_buffer->millitm = t_v.tv_usec / 1000;
- time_buffer->time = t_v.tv_sec;
+ struct timezone t_z;
+ if (gettimeofday(time_buffer, &t_z) < 0) return -1;
return 0;}
+
+struct timeval your_base = {0, 0};
+# define TIMETRIES 10
+SCM your_time()
+{
+ long tmp;
+ struct timeval time_buffer1;
+ struct timeval time_buffer2;
+ int cnt = 0;
+ tryagain:
+ cnt++;
+ scm_ftime(&time_buffer1);
+ scm_ftime(&time_buffer2);
+ if (time_buffer1.tv_sec==time_buffer2.tv_sec) {
+ if (time_buffer1.tv_usec > time_buffer2.tv_usec)
+ time_buffer2.tv_sec = time_buffer2.tv_sec + 1;
+ }
+ else if ((1 + time_buffer1.tv_sec)==time_buffer2.tv_sec) ;
+ else if (cnt < TIMETRIES) goto tryagain;
+ else { /* could not read two ftime()s within one second in 10 tries */
+ scm_warn("ftime()s too fast", "", MAKINUM(TIMETRIES));
+ return MAKINUM(-1);
+ }
+ tmp = CLKTCK*(time_buffer2.tv_usec - your_base.tv_usec);
+ tmp = CLKTCK*(time_buffer2.tv_sec - your_base.tv_sec) + tmp/1000000;
+ return MAKINUM(tmp);
+}
# else /* USE_GETTIMEOFDAY */
# define scm_ftime ftime
-# endif /* USE_GETTIMEOFDAY */
struct timeb your_base = {0};
# define TIMETRIES 10
SCM your_time()
@@ -346,6 +367,7 @@ SCM your_time()
tmp = CLKTCK*(time_buffer2.time - your_base.time) + tmp/1000;
return MAKINUM(tmp);
}
+# endif /* USE_GETTIMEOFDAY */
#endif /* LACK_FTIME */
long my_base = 0;