Re: buffer flushing
On Tue, 11 May 1999, Robert Craig wrote:
] Brian Jackson writes:
] > Does anyone know of a way to flush a file buffer
] > on an open file (other than closing and then re-opening it?)
]
] Closing the file is currently the only way.
] In the next major release I'll add a flush() routine.
]
] Regards,
] Rob Craig
Here's an on-the-fly solution that uses the "close-reopen" trick. It's
coded so that it can be put straight into an .E library.
-- Initialise the trick:
sequence open_log
open_log = repeat(0,25) -- Or whatever Eu's MAX_FILES_LIMIT is...
-- redefine the open and close subroutines to use open_log:
function old_open(sequence name, sequence mode)
return open(name, mode)
end function
procedure old_close(integer handle)
close(handle)
end procedure
without warning -- me about redefinitions
global function open(sequence name, sequence mode)
integer handle
handle = old_open(name, mode)
if handle = -1 then return -1 end if
open_log[handle] = {name, mode}
return handle
end function
global procedure close(integer handle)
if handle < 3 or handle > 25 or atom(open_log[handle]) then
return
end if
open_log[handle] = 0
old_close(handle)
end procedure
with warning -- of other stuff :)
-- and now the new flush procedure:
global procedure flush(integer handle)
object info
if handle < 3 or handle > 25 then return end if
info = open_log[handle]
if atom(info) then return end if
old_close(handle) -- use old close for speed, checks already done...
if info[2][1] = 'r' then return end if -- only flush writeable files
old_open(info[1], info[2]) -- using the new open isn't necessary.
end procedure
HTH,
Carl
--
Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek
aka Cyrek -- No hyphens :) -- Bigfoot URL Alias
|
Not Categorized, Please Help
|
|