diff options
author | Jacques Garrigue <garrigue at math.nagoya-u.ac.jp> | 1999-12-21 13:58:12 +0000 |
---|---|---|
committer | Jacques Garrigue <garrigue at math.nagoya-u.ac.jp> | 1999-12-21 13:58:12 +0000 |
commit | 4f9a5ee37b2024e7ba1a2d5002be179a9340e379 (patch) | |
tree | 8236c9dd9ebb6a8e8869979fa29a718faa707981 /otherlibs/labltk/browser/useunix.ml | |
parent | 4c16e2165274ff208ba1b2a5ed188dca487def69 (diff) |
clean-up error handling code
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2706 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/labltk/browser/useunix.ml')
-rw-r--r-- | otherlibs/labltk/browser/useunix.ml | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/otherlibs/labltk/browser/useunix.ml b/otherlibs/labltk/browser/useunix.ml index f65f78c0d..9d29cc050 100644 --- a/otherlibs/labltk/browser/useunix.ml +++ b/otherlibs/labltk/browser/useunix.ml @@ -16,17 +16,21 @@ open Unix let get_files_in_directory dir = - try - let dirh = opendir dir in - let rec get_them () = - try - let x = readdir dirh in - x :: get_them () - with - _ -> closedir dirh; [] - in - Sort.list order:(<) (get_them ()) - with Unix_error _ -> [] + match + try Some(opendir dir) with Unix_error _ -> None + with + None -> [] + | Some dirh -> + let rec get_them l = + match + try Some(readdir dirh) with _ -> None + with + | Some x -> + get_them (x::l) + | None -> + closedir dirh; l + in + Sort.list order:(<=) (get_them []) let is_directory name = try @@ -39,11 +43,13 @@ let get_directories_in_files :path = (************************************************** Subshell call *) let subshell :cmd = let rc = open_process_in cmd in - let rec it () = - try - let x = input_line rc in x :: it () - with _ -> [] + let rec it l = + match + try Some(input_line rc) with _ -> None + with + Some x -> it (x::l) + | None -> List.rev l in - let answer = it () in + let answer = it [] in ignore (close_process_in rc); answer |