diff options
-rw-r--r-- | otherlibs/unix/unixsupport.c | 26 | ||||
-rw-r--r-- | otherlibs/unix/unixsupport.h | 1 |
2 files changed, 18 insertions, 9 deletions
diff --git a/otherlibs/unix/unixsupport.c b/otherlibs/unix/unixsupport.c index 2a723924c..8a42072f7 100644 --- a/otherlibs/unix/unixsupport.c +++ b/otherlibs/unix/unixsupport.c @@ -247,23 +247,31 @@ int error_table[] = { static value * unix_error_exn = NULL; +value unix_error_of_code (int errcode) +{ + int errconstr; + value err; + + errconstr = + cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1); + if (errconstr == Val_int(-1)) { + err = alloc_small(1, 0); + Field(err, 0) = Val_int(errcode); + } else { + err = errconstr; + } + return err; +} + void unix_error(int errcode, char *cmdname, value cmdarg) { value res; value name = Val_unit, err = Val_unit, arg = Val_unit; - int errconstr; 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_small(1, 0); - Field(err, 0) = Val_int(errcode); - } else { - err = errconstr; - } + err = unix_error_of_code (errcode); if (unix_error_exn == NULL) { unix_error_exn = caml_named_value("Unix.Unix_error"); if (unix_error_exn == NULL) diff --git a/otherlibs/unix/unixsupport.h b/otherlibs/unix/unixsupport.h index e51753afa..84179f43f 100644 --- a/otherlibs/unix/unixsupport.h +++ b/otherlibs/unix/unixsupport.h @@ -19,6 +19,7 @@ #define Nothing ((value) 0) +extern value unix_error_of_code (int errcode); extern void unix_error (int errcode, char * cmdname, value arg) Noreturn; extern void uerror (char * cmdname, value arg) Noreturn; |