Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

235 ^M are not read by really_input #2593

Closed
vicuna opened this issue Oct 20, 2000 · 2 comments
Closed

235 ^M are not read by really_input #2593

vicuna opened this issue Oct 20, 2000 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 20, 2000

Original bug ID: 208
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: mattias waldau
Version: 3.00
OS: windows 2000
Submission from: dialup-31.abc.se (195.17.73.31)

Using O'Caml 3.00, Windows 2000.

I am trying to read in a whole file into a string using the following predicate.
Note that I have to remove 235 (probably since there are 235 ^M in the file),
otherwise I get an end-of-file error. channel_length is doing correctly and
returning 24961.

(* 649 1800 24961 c:/stock/www.dljdirect.com/20000722151743.html
*)

let read_all2 filename =
let ic = open_in filename in
let size = in_channel_length ic in
let buf = String.create size in
let _ = really_input ic buf 0 (size-235) in
close_in ic;
buf
;;

read_all2 "c:/stock/www.dljdirect.com/20000722151743.html";;

P.s. How should I attach the file?


Mattias Waldau, CTO
Tacton AB, Saltmätargatan 7, 11359 Stockholm
Mobile +46 70 549 11 12
http://www.tacton.com mailto:mattias.waldau@tacton.com

@vicuna
Copy link
Author

vicuna commented Oct 22, 2000

Comment author: administrator

Full_Name: mattias waldau
Version: 3.00
OS: windows 2000
Submission from: dialup-31.abc.se (195.17.73.31)

Using O'Caml 3.00, Windows 2000.

I am trying to read in a whole file into a string using the following predicate.

You mean function not predicate, do you ?

Note that I have to remove 235 (probably since there are 235 ^M in the file),
otherwise I get an end-of-file error. channel_length is doing correctly and
returning 24961.

(* 649 1800 24961 c:/stock/www.dljdirect.com/20000722151743.html
*)

let read_all2 filename =
let ic = open_in filename in
let size = in_channel_length ic in
let buf = String.create size in
let _ = really_input ic buf 0 (size-235) in
close_in ic;
buf
;;

read_all2 "c:/stock/www.dljdirect.com/20000722151743.html";;

P.s. How should I attach the file?


Mattias Waldau, CTO
Tacton AB, Saltmätargatan 7, 11359 Stockholm
Mobile +46 70 549 11 12
http://www.tacton.com mailto:mattias.waldau@tacton.com

Your problem is that you opened your file in text mode, instead of
binary mode. Thus end-of-line markers are omitted from the input
count.

You can use open_in_bin if you want to have the exact count of the
characters written into the file. However this is not portable, since
end-of-line markers are not the same under Unix, MacOS and Windows...

This suggest to add a function into the standard library to read a
file into a string (or more generally a buffer). Thus, I would suggest
the names buffer_of_file and string_of_file for such functions ...

Hope this helps,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/

@vicuna
Copy link
Author

vicuna commented Nov 6, 2002

Comment author: administrator

User's misunderstanding of text mode vs. binary mode. Suggestion to add file
reading functions to std lib. (See #2559)

@vicuna vicuna closed this as completed Nov 6, 2002
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant