patch-time_c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. $OpenBSD: patch-time_c,v 1.4 2013/12/06 19:55:39 espie Exp $
  2. --- time.c.orig Thu Jan 31 04:33:06 2008
  3. +++ time.c Fri Dec 6 20:54:39 2013
  4. @@ -20,6 +20,11 @@
  5. #include "scm.h"
  6. +#ifdef __unix__
  7. +# ifndef unix
  8. +# define unix 1
  9. +# endif
  10. +#endif
  11. #ifdef STDC_HEADERS
  12. # include <time.h>
  13. # ifdef M_SYSV
  14. @@ -104,7 +109,6 @@
  15. #ifdef __OpenBSD__
  16. # include <sys/types.h>
  17. # include <sys/time.h>
  18. -# include <sys/timeb.h>
  19. # define USE_GETTIMEOFDAY
  20. #endif
  21. #ifdef __TURBOC__
  22. @@ -169,6 +173,7 @@
  23. # define USE_GETTIMEOFDAY
  24. #endif
  25. +#ifndef USE_GETTIMEOFDAY
  26. #ifndef LACK_FTIME
  27. # ifdef HAVE_UNIX
  28. # ifndef GO32
  29. @@ -176,6 +181,7 @@
  30. # endif
  31. # endif
  32. #endif
  33. +#endif
  34. #ifdef __EMX__
  35. # define LACK_TIMES
  36. @@ -308,18 +314,40 @@ SCM your_time()
  37. #else /* LACK_FTIME */
  38. # ifdef USE_GETTIMEOFDAY
  39. int scm_ftime(time_buffer)
  40. - struct timeb *time_buffer;
  41. + struct timeval *time_buffer;
  42. {
  43. - struct timezone t_z; struct timeval t_v;
  44. - if (gettimeofday(&t_v, &t_z) < 0) return -1;
  45. - time_buffer->timezone = t_z.tz_minuteswest;
  46. - time_buffer->dstflag = t_z.tz_dsttime;
  47. - time_buffer->millitm = t_v.tv_usec / 1000;
  48. - time_buffer->time = t_v.tv_sec;
  49. + struct timezone t_z;
  50. + if (gettimeofday(time_buffer, &t_z) < 0) return -1;
  51. return 0;}
  52. +
  53. +struct timeval your_base = {0, 0};
  54. +# define TIMETRIES 10
  55. +SCM your_time()
  56. +{
  57. + long tmp;
  58. + struct timeval time_buffer1;
  59. + struct timeval time_buffer2;
  60. + int cnt = 0;
  61. + tryagain:
  62. + cnt++;
  63. + scm_ftime(&time_buffer1);
  64. + scm_ftime(&time_buffer2);
  65. + if (time_buffer1.tv_sec==time_buffer2.tv_sec) {
  66. + if (time_buffer1.tv_usec > time_buffer2.tv_usec)
  67. + time_buffer2.tv_sec = time_buffer2.tv_sec + 1;
  68. + }
  69. + else if ((1 + time_buffer1.tv_sec)==time_buffer2.tv_sec) ;
  70. + else if (cnt < TIMETRIES) goto tryagain;
  71. + else { /* could not read two ftime()s within one second in 10 tries */
  72. + scm_warn("ftime()s too fast", "", MAKINUM(TIMETRIES));
  73. + return MAKINUM(-1);
  74. + }
  75. + tmp = CLKTCK*(time_buffer2.tv_usec - your_base.tv_usec);
  76. + tmp = CLKTCK*(time_buffer2.tv_sec - your_base.tv_sec) + tmp/1000000;
  77. + return MAKINUM(tmp);
  78. +}
  79. # else /* USE_GETTIMEOFDAY */
  80. # define scm_ftime ftime
  81. -# endif /* USE_GETTIMEOFDAY */
  82. struct timeb your_base = {0};
  83. # define TIMETRIES 10
  84. SCM your_time()
  85. @@ -346,6 +374,7 @@ SCM your_time()
  86. tmp = CLKTCK*(time_buffer2.time - your_base.time) + tmp/1000;
  87. return MAKINUM(tmp);
  88. }
  89. +# endif /* USE_GETTIMEOFDAY */
  90. #endif /* LACK_FTIME */
  91. long my_base = 0;