import PreludeIOError
import PreludeGlaST
import PS
+import LibPosixUtil (allocWords, allocChars)
\end{code}
instance Text ClockTime where
showsPrec p (TOD sec@(J# a# s# d#) nsec) =
showString (unsafePerformPrimIO (
- _ccall_ showTime (I# s#) (_ByteArray (error "ClockTime.show") d#)
+ allocChars 32 `thenPrimIO` \ buf ->
+ _ccall_ showTime (I# s#) (_ByteArray (error "ClockTime.show") d#) buf
`thenPrimIO` \ str ->
_ccall_ strlen str `thenPrimIO` \ len ->
_packCBytesST len str `thenStrictlyST` \ ps ->
\begin{code}
toCalendarTime :: ClockTime -> CalendarTime
toCalendarTime (TOD sec@(J# a# s# d#) psec) = unsafePerformPrimIO (
- _ccall_ toLocalTime (I# s#) (_ByteArray (error "toCalendarTime") d#)
+ allocWords (``sizeof(struct tm)''::Int) `thenPrimIO` \ res ->
+ allocChars 32 `thenPrimIO` \ zoneNm ->
+ _casm_ ``SETZONE((struct tm *)%0,(char *)%1); '' res zoneNm `thenPrimIO` \ () ->
+ _ccall_ toLocalTime (I# s#) (_ByteArray (error "toCalendarTime") d#) res
`thenPrimIO` \ tm ->
if tm == (``NULL''::_Addr) then
error "toCalendarTime{LibTime}: out of range"
`thenPrimIO` \ yday ->
_casm_ ``%r = ((struct tm *)%0)->tm_isdst;'' tm
`thenPrimIO` \ isdst ->
- _ccall_ ZONE tm `thenPrimIO` \ zone ->
- _ccall_ GMTOFF tm `thenPrimIO` \ tz ->
+ _ccall_ ZONE tm `thenPrimIO` \ zone ->
+ _ccall_ GMTOFF tm `thenPrimIO` \ tz ->
_ccall_ strlen zone `thenPrimIO` \ len ->
_packCBytesST len zone `thenStrictlyST` \ tzname ->
returnPrimIO (CalendarTime (1900+year) mon mday hour min sec psec
toUTCTime :: ClockTime -> CalendarTime
toUTCTime (TOD sec@(J# a# s# d#) psec) = unsafePerformPrimIO (
- _ccall_ toUTCTime (I# s#) (_ByteArray (error "toCalendarTime") d#)
+ allocWords (``sizeof(struct tm)''::Int) `thenPrimIO` \ res ->
+ allocChars 32 `thenPrimIO` \ zoneNm ->
+ _casm_ ``SETZONE((struct tm *)%0,(char *)%1); '' res zoneNm `thenPrimIO` \ () ->
+ _ccall_ toUTCTime (I# s#) (_ByteArray (error "toCalendarTime") d#) res
`thenPrimIO` \ tm ->
if tm == (``NULL''::_Addr) then
error "toUTCTime{LibTime}: out of range"
error "toClockTime{LibTime}: timezone offset out of range"
else
unsafePerformPrimIO (
- _ccall_ toClockSec year mon mday hour min sec tz
+ allocWords (``sizeof(time_t)'') `thenPrimIO` \ res ->
+ _ccall_ toClockSec year mon mday hour min sec tz res
`thenPrimIO` \ ptr@(A# ptr#) ->
if ptr /= ``NULL'' then
returnPrimIO (TOD (int2Integer# (indexIntOffAddr# ptr# 0#)) psec)