Commit ed18827b authored by Rodolphe Lepigre's avatar Rodolphe Lepigre Committed by Michael Sammler
Browse files

Better error handling with [realpath] + bug fix.

parent 1943211d
Pipeline #42822 passed with stage
in 18 minutes and 56 seconds
......@@ -114,13 +114,13 @@ let run : config -> string -> unit = fun cfg c_file ->
Coq_pp.print_stmt_locs := false
end;
(* Split the file path into a file name and absolute directory path. *)
let c_file =
try Filename.realpath c_file with Invalid_argument(_) ->
panic "File [%s] disappeared..." c_file
in
let c_file_name = Filename.basename c_file in
let c_file_name_no_ext = Filename.remove_extension c_file_name in
let c_file_dir =
let c_file_dir = Filename.dirname c_file in
try Filename.realpath c_file_dir with Invalid_argument(_) ->
panic "Directory [%s] disappeared..." c_file_dir
in
let c_file_dir = Filename.dirname c_file in
(* Locate the RefinedC project root and the relitive logical directory. *)
let find_root_and_dir_path dir =
let rec find acc dir =
......
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/fail.h>
......@@ -10,8 +11,29 @@ CAMLprim value c_realpath(value v) {
char *output_path = realpath(input_path, NULL);
// Checking for error.
if (output_path == NULL)
caml_invalid_argument("Extra.Filename.realpath\0");
if (output_path == NULL){
switch(errno){
case EACCES:
caml_invalid_argument("Extra.Filename.realpath (EACCESS)\0");
case EINVAL:
caml_invalid_argument("Extra.Filename.realpath (EINVAL)\0");
case EIO:
caml_invalid_argument("Extra.Filename.realpath (EIO)\0");
case ELOOP:
caml_invalid_argument("Extra.Filename.realpath (ELOOP)\0");
case ENAMETOOLONG:
caml_invalid_argument("Extra.Filename.realpath (ENAMETOOLONG)\0");
case ENOENT:
caml_invalid_argument("Extra.Filename.realpath (ENOENT)\0");
case ENOMEM:
caml_invalid_argument("Extra.Filename.realpath (ENOMEM)\0");
case ENOTDIR:
caml_invalid_argument("Extra.Filename.realpath (ENOTDIR)\0");
default:
// Should not be reachable.
caml_invalid_argument("Extra.Filename.realpath (unknown)\0");
}
}
// Preparing the result value.
value res = caml_copy_string(output_path);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment