From: Nicolas C. <war...@fr...> - 2004-04-03 09:33:47
|
> > In the implementation, you assume string is null-termintated (in > > read_string) and int is 32-bit long (in write_ui32). Both are not the > > case in OCaml. > > more idea on write_string/read_string. > > How about that write_string terminates a string by one of new line > characters, and read_string recognize all of LF, CRLF, CR? The line > I/O would be worthy addition. I agree with the string's suggestions, and propose the following : a pair of functions : - read_line / write_line that are recognizing LF/CRLF (not CR because we cannot push back readed data into the IO) - by default write_line will write an additionnal LF and if not opened in binary mode the underlying channel will convert it to CRLF on windows system. - keep read_string / write_string for null-terminated string (it makes sense since all theses additionnal API are made to work easily with C-generated binary files ) I will also add the write_i32/read_i32 functions : negative caml int should be accepted and converted to corresponding C-32-bits-represented negative value. Of course I'm here working here with 31 bits values so the bit we're loosing is the highest - before sign - one. We can add later write_real_i32 that will work with caml int32 type but for efficiency reasons the user can choose to use write_i32 as long there is exception guard to check overflows :-) Regards, Nicolas Cannasse |