File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -132,14 +132,15 @@ module Sysfs = struct
132132
133133 let read_one_line file =
134134 try
135- let inchan = open_in file in
136- Pervasiveext. finally
137- ( fun () -> input_line inchan)
138- ( fun () -> close_in inchan )
135+ Unixext. string_of_file file
136+ |> String. split_on_char '\n'
137+ |> List. hd
138+ (* Note: the list returned by split_on_char is guaranteed to be non-empty * )
139139 with
140140 | End_of_file -> " "
141- (* Match the exception when the device state if off *)
142- | Sys_error ("Invalid argument" ) -> raise (Network_error (Read_error file))
141+ | Unix. Unix_error (Unix. EINVAL, _ , _ ) ->
142+ (* The device is not yet up *)
143+ raise (Network_error (Read_error file))
143144 | exn ->
144145 error " Error in read one line of file: %s, exception %s\n %s"
145146 file (Printexc. to_string exn ) (Printexc. get_backtrace () );
You can’t perform that action at this time.
0 commit comments