diff options
-rw-r--r-- | otherlibs/unix/unixsupport.c | 4 | ||||
-rw-r--r-- | otherlibs/win32unix/unixsupport.c | 28 |
2 files changed, 18 insertions, 14 deletions
diff --git a/otherlibs/unix/unixsupport.c b/otherlibs/unix/unixsupport.c index b576ebe9a..157ac2635 100644 --- a/otherlibs/unix/unixsupport.c +++ b/otherlibs/unix/unixsupport.c @@ -253,11 +253,11 @@ void unix_error(int errcode, char *cmdname, value cmdarg) name = copy_string(cmdname); errconstr = cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1); - if (errconstr == -1) { + if (errconstr == Val_int(-1)) { err = alloc(1, 0); Field(err, 0) = Val_int(errcode); } else { - err = Val_int(errconstr); + err = errconstr; } if (unix_error_exn == NULL) { unix_error_exn = caml_named_value("Unix.Unix_error"); diff --git a/otherlibs/win32unix/unixsupport.c b/otherlibs/win32unix/unixsupport.c index 8a2bb0fc2..e631ccbdb 100644 --- a/otherlibs/win32unix/unixsupport.c +++ b/otherlibs/win32unix/unixsupport.c @@ -88,27 +88,31 @@ int error_table[] = { static value * unix_error_exn = NULL; -void unix_error(errcode, cmdname, cmdarg) - int errcode; - char * cmdname; - value cmdarg; +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 == Val_int(-1)) { + err = alloc(1, 0); + Field(err, 0) = Val_int(errcode); + } else { + err = 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, must link unix.cma"); + 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(); |