diff options
-rw-r--r-- | otherlibs/unix/errmsg.c | 4 | ||||
-rw-r--r-- | otherlibs/unix/unix.ml | 4 | ||||
-rw-r--r-- | otherlibs/unix/unix.mli | 2 | ||||
-rw-r--r-- | otherlibs/unix/unixsupport.c | 21 |
4 files changed, 19 insertions, 12 deletions
diff --git a/otherlibs/unix/errmsg.c b/otherlibs/unix/errmsg.c index c802bc3f4..d6aff93bd 100644 --- a/otherlibs/unix/errmsg.c +++ b/otherlibs/unix/errmsg.c @@ -24,7 +24,7 @@ extern char * strerror(int); value unix_error_message(value err) { int errnum; - errnum = error_table[Int_val(err)]; + errnum = Is_block(err) ? Int_val(Field(err, 0)) : error_table[Int_val(err)]; return copy_string(strerror(errnum)); } @@ -36,7 +36,7 @@ extern char *sys_errlist[]; value unix_error_message(value err) { int errnum; - errnum = error_table[Int_val(err)]; + errnum = Is_block(err) ? Int_val(Field(err, 0)) : error_table[Int_val(err)]; if (errnum < 0 || errnum >= sys_nerr) { return copy_string("Unknown error"); } else { diff --git a/otherlibs/unix/unix.ml b/otherlibs/unix/unix.ml index c27dc83ac..1f2b35c19 100644 --- a/otherlibs/unix/unix.ml +++ b/otherlibs/unix/unix.ml @@ -79,12 +79,12 @@ type error = | EHOSTDOWN | EHOSTUNREACH | ELOOP - | EUNKNOWNERR + | EUNKNOWNERR of int exception Unix_error of error * string * string let _ = Callback.register_exception "Unix.Unix_error" - (Unix_error(EUNKNOWNERR, "", "")) + (Unix_error(E2BIG, "", "")) external error_message : error -> string = "unix_error_message" diff --git a/otherlibs/unix/unix.mli b/otherlibs/unix/unix.mli index 45232fe6e..100d85c6b 100644 --- a/otherlibs/unix/unix.mli +++ b/otherlibs/unix/unix.mli @@ -86,7 +86,7 @@ type error = | EHOSTUNREACH (* No route to host *) | ELOOP (* Too many levels of symbolic links *) (* All other errors are mapped to EUNKNOWNERR *) - | EUNKNOWNERR (* Unknown error *) + | EUNKNOWNERR of int (* Unknown error *) (* The type of error codes. *) diff --git a/otherlibs/unix/unixsupport.c b/otherlibs/unix/unixsupport.c index ebdcf3940..b576ebe9a 100644 --- a/otherlibs/unix/unixsupport.c +++ b/otherlibs/unix/unixsupport.c @@ -245,21 +245,28 @@ static value * unix_error_exn = NULL; void unix_error(int errcode, char *cmdname, value cmdarg) { value res; - value name = Val_unit, arg = Val_unit; + value name = Val_unit, err = Val_unit, arg = Val_unit; + int errconstr; - Begin_roots2 (name, arg); + Begin_roots3 (name, err, arg); + arg = cmdarg == Nothing ? copy_string("") : cmdarg; + name = copy_string(cmdname); + errconstr = + cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1); + if (errconstr == -1) { + err = alloc(1, 0); + Field(err, 0) = Val_int(errcode); + } else { + err = Val_int(errconstr); + } if (unix_error_exn == NULL) { unix_error_exn = caml_named_value("Unix.Unix_error"); if (unix_error_exn == NULL) invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma"); } - arg = cmdarg == Nothing ? copy_string("") : cmdarg; - name = copy_string(cmdname); res = alloc(4, 0); Field(res, 0) = *unix_error_exn; - Field(res, 1) = - cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), - sizeof(error_table)/sizeof(int)); + Field(res, 1) = err; Field(res, 2) = name; Field(res, 3) = arg; End_roots(); |