Re: buffer flushing

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Thu, 13 May 1999, Lucius Hilley III wrote:

] I think you only want to flush/close files if they are writable.
] That means you want to move your close() statement in flush()
] below your if "read only" statement.
] I also suggest you alter your r to be a find 'r'
] "rb" is possible.
] even then if you don't close a readable file you will
] want to use seek() to return to the beginning of the file.
]
] -- Lucius L. Hilley III
]
] On Thu, 13 May 1999 14:42:16 +0100, Carl R. White

1 >global procedure flush(integer handle)
2 >    object info
3 >    if handle < 3 or handle > 25 then return end if
4 >    info = open_log[handle]
5 >    if atom(info) then return end if
6 >    old_close(handle) -- use old close for speed, checks already done...
7 >    if info[2][1] = 'r' then return end if -- only flush writeable files
8 >    old_open(info[1], info[2]) -- using the new open isn't necessary.
9 >end procedure

I did say it was on-the-fly... :)

I can't say that seeking to the beginning of the file is what would be
required of a flush on a read-mode file. I think just ignoring the
request is more correct (MHO).

As for the "only flush writable" 'if', that's correct code. I'm checking
the first element for either "r" or "rb", which would be 'r' in either
case. The first element *has* to be there, so length checking isn't
necessary. old_open() wouldn't have let the new open() put it in
open_log[] if the syntax had been incorrect...

The old_close() call, however, *is* in the wrong place. Well spotted.
<warner_cartoon voice="Sylvester">
Thimply thwap lineth thix and theven for a corrected function.

Lament: Thilly bugth do thilly programth make...
</w_c>
Carl - in a thilly mood.

--
Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek
 aka Cyrek   --    No hyphens :)    --       Bigfoot URL Alias

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu