Skip to content

Commit 86dcc59

Browse files
committed
Eliminate compiler warning 52
Signed-off-by: Rob Hoes <[email protected]>
1 parent 0971cb5 commit 86dcc59

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/network_utils.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff 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 ());

0 commit comments

Comments
 (0)