File: gmtime_max.m4

package info (click to toggle)
dovecot 1%3A2.4.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 46,224 kB
  • sloc: ansic: 596,204; makefile: 7,825; sh: 6,005; cpp: 1,866; perl: 487; yacc: 412; lex: 320; python: 253; xml: 232
file content (41 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
dnl * how large time_t values does gmtime() accept?
AC_DEFUN([DOVECOT_GMTIME_MAX], [
  AC_CACHE_CHECK([how large time_t values gmtime() accepts],i_cv_gmtime_max_time_t,[
    AC_RUN_IFELSE([AC_LANG_PROGRAM([[
      #include <stdio.h>
      #include <time.h>
      ]], [[
        FILE *f;
        int bits;
    
        for (bits = 1; bits < sizeof(time_t)*8; bits++) {
          time_t t = ((time_t)1 << bits) - 1;
          if (gmtime(&t) == NULL) {
            bits--;
            break;
          }
        }
        if (bits > 40) {
          /* Solaris 9 breaks after 55 bits. Perhaps other systems break earlier.
             Let's just do the same as Cyrus folks and limit it to 40 bits. */
          bits = 40;
        }
    
        f = fopen("conftest.temp", "w");
        if (f == NULL) {
          perror("fopen()");
          return 1;
        }
        fprintf(f, "%d", bits);
        fclose(f);
        return 0;
    ]])],[
      i_cv_gmtime_max_time_t=`cat conftest.temp`
      rm -f conftest.temp
    ], [
      printf "check failed, assuming "
      i_cv_gmtime_max_time_t=31
    ],[])
  ])
  AC_DEFINE_UNQUOTED(TIME_T_MAX_BITS, $i_cv_gmtime_max_time_t, [max. time_t bits gmtime() can handle])
])