Commits

Barry Schwartz committed 8e84af7

Use the size of time_t (found by configure) to determine the kind of fortran int for conversion to/from ot_longdatetime.

Comments (0)

Files changed (2)

fortran/font/configure.ac

 
 # Checks for libraries.
 
+dnl AC_FUNC_MMAP
+
 dnl dnl --- FIXME: Provide an alternative to TIME8() for non-GNU compilers.
 dnl dnl
 dnl dnl AC_MSG_CHECKING([for TIME8 Fortran intrinsic (GNU extension)])
 
 # Checks for typedefs, structures, and compiler characteristics.
 
+AC_CHECK_SIZEOF([time_t],[],[
+AC_INCLUDES_DEFAULT
+#include <sys/time.h>
+#include <time.h>
+])
+
 AC_FC_FREEFORM
 AC_FC_LINE_LENGTH
 if test "x$ac_cv_fc_compiler_gnu" = xyes; then

fortran/font/opentype_longdatetime.F90

 
 !--------------------------------------------------------------------------
 
+#ifndef SIZEOF_TIME_T
+#define SIZEOF_TIME_T 8
+#endif
+
 module opentype_longdatetime
   use iso_fortran_env
   implicit none
 
+  integer, parameter :: ot_time_t = &
+       selected_int_kind(int(ceiling((8*SIZEOF_TIME_T - 1)*log10(2.0))))
+
   ! 1 January 1904 00:00:00 UT, to within leap seconds, expressed in
   ! seconds relative to the Unix epoch.
-  integer(int64), parameter :: ot_epoch = -2082844800_int64
+  integer(ot_time_t), parameter :: ot_epoch = -2082844800_ot_time_t
 
   type :: ot_longdatetime
      integer(int8), dimension(8) :: val
 contains
 
   elemental function ot_longdatetime_of_int(i_time) result(b)
-    integer(int64), intent(in) :: i_time
+    integer(ot_time_t), intent(in) :: i_time
     type(ot_longdatetime) :: b
 
-    integer(int64) :: i
+    integer(ot_time_t) :: i
 
     ! Convert from Unix time to OpenType time.
     i = i_time - ot_epoch
 
-    b%val = [int(iand(shiftr(i,56),255_int64), kind=int8), &
-         int(iand(shiftr(i,48),255_int64), kind=int8), &
-         int(iand(shiftr(i,40),255_int64), kind=int8), &
-         int(iand(shiftr(i,32),255_int64), kind=int8), &
-         int(iand(shiftr(i,24),255_int64), kind=int8), &
-         int(iand(shiftr(i,16),255_int64), kind=int8), &
-         int(iand(shiftr(i,8),255_int64), kind=int8), &
-         int(iand(i,255_int64), kind=int8)]
+    b%val = [int(iand(shiftr(i,56),255_ot_time_t), kind=int8), &
+         int(iand(shiftr(i,48),255_ot_time_t), kind=int8), &
+         int(iand(shiftr(i,40),255_ot_time_t), kind=int8), &
+         int(iand(shiftr(i,32),255_ot_time_t), kind=int8), &
+         int(iand(shiftr(i,24),255_ot_time_t), kind=int8), &
+         int(iand(shiftr(i,16),255_ot_time_t), kind=int8), &
+         int(iand(shiftr(i,8),255_ot_time_t), kind=int8), &
+         int(iand(i,255_ot_time_t), kind=int8)]
   end function ot_longdatetime_of_int
 
   elemental function ot_longdatetime_of_default_int(i_time) result(b)
     integer, intent(in) :: i_time
     type(ot_longdatetime) :: b
-    b = ot_longdatetime_of_int(int(i_time, kind=int64))
+    b = ot_longdatetime_of_int(int(i_time, kind=ot_time_t))
   end function ot_longdatetime_of_default_int
 
   elemental function int_of_ot_longdatetime(b) result(i_time)
-    integer(int64) :: i_time
+    integer(ot_time_t) :: i_time
     type(ot_longdatetime), intent(in) :: b
 
-    integer(int64) :: i
+    integer(ot_time_t) :: i
 
-    i = ior(shiftl(int(b%val(1), kind=int64), 56), &
-         ior(shiftl(iand(int(b%val(2), kind=int64), 255_int64), 48), &
-         ior(shiftl(iand(int(b%val(3), kind=int64), 255_int64), 40), &
-         ior(shiftl(iand(int(b%val(4), kind=int64), 255_int64), 32), &
-         ior(shiftl(iand(int(b%val(5), kind=int64), 255_int64), 24), &
-         ior(shiftl(iand(int(b%val(6), kind=int64), 255_int64), 16), &
-         ior(shiftl(iand(int(b%val(7), kind=int64), 255_int64), 8), &
-         iand(int(b%val(8), kind=int64), 255_int64))))))))
+    i = ior(shiftl(int(b%val(1), kind=ot_time_t), 56), &
+         ior(shiftl(iand(int(b%val(2), kind=ot_time_t), 255_ot_time_t), 48), &
+         ior(shiftl(iand(int(b%val(3), kind=ot_time_t), 255_ot_time_t), 40), &
+         ior(shiftl(iand(int(b%val(4), kind=ot_time_t), 255_ot_time_t), 32), &
+         ior(shiftl(iand(int(b%val(5), kind=ot_time_t), 255_ot_time_t), 24), &
+         ior(shiftl(iand(int(b%val(6), kind=ot_time_t), 255_ot_time_t), 16), &
+         ior(shiftl(iand(int(b%val(7), kind=ot_time_t), 255_ot_time_t), 8), &
+         iand(int(b%val(8), kind=ot_time_t), 255_ot_time_t))))))))
 
     ! Convert from OpenType time to Unix time.
     i_time = i + ot_epoch
 
   open(newunit=unit, file='a.out.COPY', action='readwrite', status='unknown', access='stream')
 
-  write(unit, pos=10) ot_longdatetime(9223372036854775807_int64)
+  write(unit, pos=10) ot_longdatetime(9223372036854775807_ot_time_t)
   read(unit, pos=10) c
-  print *, 9223372036854775807_int64, ' => ', int(c)
+  print *, 9223372036854775807_ot_time_t, ' => ', int(c)
 
   write(unit, pos=10) ot_longdatetime([0,0,0,0,0,0,0,0])
   read(unit, pos=10) c