summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/errmsg.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2001-08-28 14:47:48 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2001-08-28 14:47:48 +0000
commitddd99c7e5d2f0f8e7364e8521fa7e8308999344e (patch)
tree3c0158d035a52c0cf185c08c3288c3c76d6718d0 /otherlibs/win32unix/errmsg.c
parentc345611817d76ccc3bbd02db1f942774220739f9 (diff)
Chargement dynamique de primitives C
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3677 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix/errmsg.c')
-rw-r--r--otherlibs/win32unix/errmsg.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/otherlibs/win32unix/errmsg.c b/otherlibs/win32unix/errmsg.c
new file mode 100644
index 000000000..7a6cf654e
--- /dev/null
+++ b/otherlibs/win32unix/errmsg.c
@@ -0,0 +1,41 @@
+/***********************************************************************/
+/* */
+/* Objective Caml */
+/* */
+/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 2001 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the GNU Library General Public License. */
+/* */
+/***********************************************************************/
+
+/* $Id$ */
+
+#include <errno.h>
+#include <string.h>
+#include <mlvalues.h>
+#include <alloc.h>
+#include "unixsupport.h"
+
+extern int error_table[];
+
+CAMLprim value unix_error_message(value err)
+{
+ int errnum;
+ char buffer[512];
+
+ errnum = Is_block(err) ? Int_val(Field(err, 0)) : error_table[Int_val(err)];
+ if (errnum > 0)
+ return copy_string(strerror(errnum));
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ -errnum,
+ 0,
+ buffer,
+ sizeof(buffer),
+ NULL))
+ return copy_string(buffer);
+ return copy_string("unknown error");
+}
+