Hi all,
It seems there is no function to read exactly n characters
into a string (ie. IO.nread just without automatically
shortening the string if EOF is hit while reading). Since
at least one person needs it (me :)) I thought I would add
this:
let really_nread i n =
if n < 0 then raise (Invalid_argument "IO.really_nread");
if n = 0 then
""
else
let s = String.create n in
let l = ref n in
let p = ref 0 in
while !l > 0 do
let r = i.in_input s !p !l in
p := !p + r;
l := !l - r;
done;
s
which is exactly the same code as IO.nread, except it
doesn't try to catch the No_more_input exception.
Any objections to adding this?
--
Bardur Arantsson
<bardur@xxxxxxxxxxxx>
<bardur@xxxxxxxxxxxxxxx>
- You've got mail! Hope you don't have stocks.
Robin Williams | Live on Broadway (2002)
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
|
Try Searching:
servers, voip, java, networking, microsoft ...
|
|
|
|