1 dnl FC_CHECK_GETTIMEOFDAY_RUNTIME(EXTRA-LIBS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
3 dnl This tests whether gettimeofday works at runtime. Here, "works"
4 dnl means: time doesn't go backward and time doesn't jump forward by
5 dnl a huge amount. It seems that glibc 2.3.1 is broken in this respect.
7 AC_DEFUN([FC_CHECK_GETTIMEOFDAY_RUNTIME],
11 AC_RUN_IFELSE([AC_LANG_SOURCE([[
21 int main(int argc, char **argv)
23 struct timeval tv[2], start, end;
26 if (gettimeofday(&start, NULL) == -1) {
30 end.tv_sec += SECONDS;
35 for (calls = 0;; calls++) {
38 if (gettimeofday(&tv[0], NULL) == -1) {
42 if (tv[0].tv_sec < tv[1].tv_sec) {
45 (tv[1].tv_sec - start.tv_sec) +
46 ((tv[1].tv_usec - start.tv_usec) / 1e6);
47 printf("after %fs: going backward by %lds\n", diff,
48 tv[1].tv_sec - tv[0].tv_sec);
53 if (tv[0].tv_sec == tv[1].tv_sec && tv[0].tv_usec < tv[1].tv_usec) {
56 (tv[1].tv_sec - start.tv_sec) +
57 ((tv[1].tv_usec - start.tv_usec) / 1e6);
58 printf("after %fs: going backward by %ldus\n", diff,
59 tv[1].tv_usec - tv[0].tv_usec);
64 if (tv[0].tv_sec > tv[1].tv_sec + 1) {
67 (tv[1].tv_sec - start.tv_sec) +
68 ((tv[1].tv_usec - start.tv_usec) / 1e6);
69 printf("after %fs: going forward by %lds\n", diff,
70 tv[0].tv_sec - tv[1].tv_sec);
77 if (abs(sec - tv[0].tv_sec) > 1) {
80 (tv[1].tv_sec - start.tv_sec) +
81 ((tv[1].tv_usec - start.tv_usec) / 1e6);
82 printf("after %fs: time() = %ld, gettimeofday = %ld, diff = %ld\n", diff,
83 (long)sec, (long)tv[0].tv_sec, sec - (long)tv[0].tv_sec);
88 if (timercmp(&tv[0], &end, >)) {
97 (tv[1].tv_sec - start.tv_sec) +
98 ((tv[1].tv_usec - start.tv_usec) / 1e6);
99 printf("%d calls in %fs = %fus/call\n", calls, diff, 1e6 * diff / calls);
104 ]])],[AC_MSG_RESULT(yes)
105 [$2]],[AC_MSG_RESULT(no)
106 [$3]],[AC_MSG_RESULT(unknown: cross-compiling)