File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 21
21
#include <caml/sys.h>
22
22
#include "unixsupport.h"
23
23
24
+ #ifdef CAML_RUNTIME_5
25
+
26
+ CAMLprim value caml_unix_error_message (value err )
27
+ {
28
+ char buf [1024 ];
29
+ int errnum = caml_unix_code_of_unix_error (err );
30
+ return caml_copy_string (caml_strerror (errnum , buf , sizeof (buf )));
31
+ }
32
+
33
+ #else
34
+
24
35
CAMLprim value caml_unix_error_message (value err )
25
36
{
26
37
char buf [1024 ];
@@ -32,3 +43,5 @@ CAMLprim value caml_unix_error_message(value err)
32
43
*/
33
44
buf );
34
45
}
46
+
47
+ #endif
Original file line number Diff line number Diff line change 24
24
extern "C" {
25
25
#endif
26
26
27
+ CAMLextern char * caml_strerror (int errnum , char * buf , size_t buflen );
28
+
27
29
#define NO_ARG Val_int(0)
28
30
29
31
CAMLnoreturn_start
Original file line number Diff line number Diff line change 61
61
#include "caml/callback.h"
62
62
#include "caml/startup_aux.h"
63
63
64
+ CAMLexport char * caml_strerror (int errnum , char * buf , size_t buflen )
65
+ {
66
+ #ifdef _WIN32
67
+ /* Windows has a thread-safe strerror */
68
+ return strerror (errnum );
69
+ #else
70
+ int res = strerror_r (errnum , buf , buflen );
71
+ /* glibc<2.13 returns -1/sets errno, >2.13 returns +ve errno.
72
+ We assume that buffer size is large enough not to get ERANGE,
73
+ so we assume we got EINVAL. */
74
+ if (res != 0 ) {
75
+ snprintf (buf , buflen , "Unknown error %d" , errnum );
76
+ }
77
+ return buf ;
78
+ #endif
79
+ }
80
+
64
81
static char * error_message (void )
65
82
{
66
83
return strerror (errno );
You can’t perform that action at this time.
0 commit comments