1996-09-05 06:32:25 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1998-10-26 11:19:32 -08:00
|
|
|
/* en Automatique. Distributed only by permission. */
|
1996-09-05 06:32:25 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <mlvalues.h>
|
1996-12-10 06:45:58 -08:00
|
|
|
#include <callback.h>
|
1996-09-05 06:32:25 -07:00
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <fail.h>
|
|
|
|
#include "unixsupport.h"
|
|
|
|
#include "cst2constr.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
|
1997-09-03 07:38:02 -07:00
|
|
|
/* Heap-allocation of Windows file handles */
|
|
|
|
|
|
|
|
value win_alloc_handle(HANDLE h)
|
|
|
|
{
|
1998-10-26 11:19:32 -08:00
|
|
|
value res = alloc_small(sizeof(HANDLE) / sizeof(value), Abstract_tag);
|
1997-09-03 07:38:02 -07:00
|
|
|
Handle_val(res) = h;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1996-09-05 06:32:25 -07:00
|
|
|
/* Windows socket errors */
|
|
|
|
|
|
|
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
|
|
|
#define EINPROGRESS WSAEINPROGRESS
|
|
|
|
#define EALREADY WSAEALREADY
|
|
|
|
#define ENOTSOCK WSAENOTSOCK
|
|
|
|
#define EDESTADDRREQ WSAEDESTADDRREQ
|
|
|
|
#define EMSGSIZE WSAEMSGSIZE
|
|
|
|
#define EPROTOTYPE WSAEPROTOTYPE
|
|
|
|
#define ENOPROTOOPT WSAENOPROTOOPT
|
|
|
|
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
|
|
|
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
|
|
|
|
#define EOPNOTSUPP WSAEOPNOTSUPP
|
|
|
|
#define EPFNOSUPPORT WSAEPFNOSUPPORT
|
|
|
|
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
|
|
|
#define EADDRINUSE WSAEADDRINUSE
|
|
|
|
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
|
|
|
#define ENETDOWN WSAENETDOWN
|
|
|
|
#define ENETUNREACH WSAENETUNREACH
|
|
|
|
#define ENETRESET WSAENETRESET
|
|
|
|
#define ECONNABORTED WSAECONNABORTED
|
|
|
|
#define ECONNRESET WSAECONNRESET
|
|
|
|
#define ENOBUFS WSAENOBUFS
|
|
|
|
#define EISCONN WSAEISCONN
|
|
|
|
#define ENOTCONN WSAENOTCONN
|
|
|
|
#define ESHUTDOWN WSAESHUTDOWN
|
|
|
|
#define ETOOMANYREFS WSAETOOMANYREFS
|
|
|
|
#define ETIMEDOUT WSAETIMEDOUT
|
|
|
|
#define ECONNREFUSED WSAECONNREFUSED
|
|
|
|
#define ELOOP WSAELOOP
|
|
|
|
#define EHOSTDOWN WSAEHOSTDOWN
|
|
|
|
#define EHOSTUNREACH WSAEHOSTUNREACH
|
|
|
|
#define EPROCLIM WSAEPROCLIM
|
|
|
|
#define EUSERS WSAEUSERS
|
|
|
|
#define EDQUOT WSAEDQUOT
|
|
|
|
#define ESTALE WSAESTALE
|
|
|
|
#define EREMOTE WSAEREMOTE
|
|
|
|
|
|
|
|
/* Errors not available under Win32 */
|
|
|
|
|
|
|
|
#define EACCESS (-1)
|
|
|
|
|
|
|
|
int error_table[] = {
|
|
|
|
E2BIG, EACCESS, EAGAIN, EBADF, EBUSY, ECHILD, EDEADLK, EDOM,
|
|
|
|
EEXIST, EFAULT, EFBIG, EINTR, EINVAL, EIO, EISDIR, EMFILE, EMLINK,
|
|
|
|
ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOEXEC, ENOLCK, ENOMEM, ENOSPC,
|
|
|
|
ENOSYS, ENOTDIR, ENOTEMPTY, ENOTTY, ENXIO, EPERM, EPIPE, ERANGE,
|
|
|
|
EROFS, ESPIPE, ESRCH, EXDEV, EWOULDBLOCK, EINPROGRESS, EALREADY,
|
|
|
|
ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT,
|
|
|
|
EPROTONOSUPPORT, ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT,
|
|
|
|
EAFNOSUPPORT, EADDRINUSE, EADDRNOTAVAIL, ENETDOWN, ENETUNREACH,
|
|
|
|
ENETRESET, ECONNABORTED, ECONNRESET, ENOBUFS, EISCONN, ENOTCONN,
|
|
|
|
ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, EHOSTDOWN,
|
|
|
|
EHOSTUNREACH, ELOOP /*, EUNKNOWNERR */
|
|
|
|
};
|
|
|
|
|
1996-11-08 06:47:07 -08:00
|
|
|
static value * unix_error_exn = NULL;
|
1996-09-05 06:32:25 -07:00
|
|
|
|
1998-08-19 06:11:47 -07:00
|
|
|
void unix_error(int errcode, char *cmdname, value cmdarg)
|
1996-09-05 06:32:25 -07:00
|
|
|
{
|
|
|
|
value res;
|
1998-08-19 06:11:47 -07:00
|
|
|
value name = Val_unit, err = Val_unit, arg = Val_unit;
|
|
|
|
int errconstr;
|
1997-05-26 10:16:31 -07:00
|
|
|
|
1998-08-19 06:11:47 -07:00
|
|
|
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)) {
|
1998-10-26 11:19:32 -08:00
|
|
|
err = alloc_small(1, 0);
|
1998-08-19 06:11:47 -07:00
|
|
|
Field(err, 0) = Val_int(errcode);
|
|
|
|
} else {
|
|
|
|
err = errconstr;
|
|
|
|
}
|
1997-05-26 10:16:31 -07:00
|
|
|
if (unix_error_exn == NULL) {
|
|
|
|
unix_error_exn = caml_named_value("Unix.Unix_error");
|
|
|
|
if (unix_error_exn == NULL)
|
1998-08-19 06:11:47 -07:00
|
|
|
invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma");
|
1997-05-26 10:16:31 -07:00
|
|
|
}
|
1998-10-26 11:19:32 -08:00
|
|
|
res = alloc_small(4, 0);
|
1997-05-26 10:16:31 -07:00
|
|
|
Field(res, 0) = *unix_error_exn;
|
1998-08-19 06:11:47 -07:00
|
|
|
Field(res, 1) = err;
|
1997-05-26 10:16:31 -07:00
|
|
|
Field(res, 2) = name;
|
|
|
|
Field(res, 3) = arg;
|
|
|
|
End_roots();
|
1996-09-05 06:32:25 -07:00
|
|
|
mlraise(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uerror(cmdname, cmdarg)
|
|
|
|
char * cmdname;
|
|
|
|
value cmdarg;
|
|
|
|
{
|
|
|
|
unix_error(errno, cmdname, cmdarg);
|
|
|
|
}
|