1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
2011-07-27 07:17:02 -07:00
|
|
|
/* OCaml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-08 08:18:32 -07:00
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <alloc.h>
|
1996-11-08 06:47:07 -08:00
|
|
|
#include <callback.h>
|
1995-05-08 08:18:32 -07:00
|
|
|
#include <memory.h>
|
|
|
|
#include <fail.h>
|
1996-09-04 07:15:31 -07:00
|
|
|
#include "unixsupport.h"
|
1995-05-08 08:18:32 -07:00
|
|
|
#include "cst2constr.h"
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#ifndef E2BIG
|
|
|
|
#define E2BIG (-1)
|
|
|
|
#endif
|
1997-03-04 02:20:43 -08:00
|
|
|
#ifndef EACCES
|
|
|
|
#define EACCES (-1)
|
1996-04-12 08:57:28 -07:00
|
|
|
#endif
|
|
|
|
#ifndef EAGAIN
|
|
|
|
#define EAGAIN (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
|
|
|
#ifndef EBADF
|
|
|
|
#define EBADF (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EBUSY
|
|
|
|
#define EBUSY (-1)
|
|
|
|
#endif
|
1995-05-08 08:18:32 -07:00
|
|
|
#ifndef ECHILD
|
|
|
|
#define ECHILD (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EDEADLK
|
|
|
|
#define EDEADLK (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EDOM
|
|
|
|
#define EDOM (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EEXIST
|
|
|
|
#define EEXIST (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-11-08 06:47:07 -08:00
|
|
|
|
1995-05-08 08:18:32 -07:00
|
|
|
#ifndef EFAULT
|
|
|
|
#define EFAULT (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EFBIG
|
|
|
|
#define EFBIG (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EINTR
|
|
|
|
#define EINTR (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EINVAL
|
|
|
|
#define EINVAL (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EIO
|
|
|
|
#define EIO (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
|
|
|
#ifndef EISDIR
|
|
|
|
#define EISDIR (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EMFILE
|
|
|
|
#define EMFILE (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EMLINK
|
|
|
|
#define EMLINK (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENAMETOOLONG
|
|
|
|
#define ENAMETOOLONG (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
|
|
|
#ifndef ENFILE
|
|
|
|
#define ENFILE (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ENODEV
|
|
|
|
#define ENODEV (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ENOENT
|
|
|
|
#define ENOENT (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ENOEXEC
|
|
|
|
#define ENOEXEC (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ENOLCK
|
|
|
|
#define ENOLCK (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENOMEM
|
|
|
|
#define ENOMEM (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
|
|
|
#ifndef ENOSPC
|
|
|
|
#define ENOSPC (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ENOSYS
|
|
|
|
#define ENOSYS (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ENOTDIR
|
|
|
|
#define ENOTDIR (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ENOTEMPTY
|
|
|
|
#define ENOTEMPTY (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENOTTY
|
|
|
|
#define ENOTTY (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENXIO
|
|
|
|
#define ENXIO (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EPERM
|
|
|
|
#define EPERM (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
|
|
|
#ifndef EPIPE
|
|
|
|
#define EPIPE (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ERANGE
|
|
|
|
#define ERANGE (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef EROFS
|
|
|
|
#define EROFS (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ESPIPE
|
|
|
|
#define ESPIPE (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ESRCH
|
|
|
|
#define ESRCH (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EXDEV
|
|
|
|
#define EXDEV (-1)
|
|
|
|
#endif
|
1995-05-08 08:18:32 -07:00
|
|
|
#ifndef EWOULDBLOCK
|
|
|
|
#define EWOULDBLOCK (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EINPROGRESS
|
|
|
|
#define EINPROGRESS (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EALREADY
|
|
|
|
#define EALREADY (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENOTSOCK
|
|
|
|
#define ENOTSOCK (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EDESTADDRREQ
|
|
|
|
#define EDESTADDRREQ (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EMSGSIZE
|
|
|
|
#define EMSGSIZE (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EPROTOTYPE
|
|
|
|
#define EPROTOTYPE (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENOPROTOOPT
|
|
|
|
#define ENOPROTOOPT (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EPROTONOSUPPORT
|
|
|
|
#define EPROTONOSUPPORT (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ESOCKTNOSUPPORT
|
|
|
|
#define ESOCKTNOSUPPORT (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EOPNOTSUPP
|
2011-12-21 05:08:48 -08:00
|
|
|
# ifdef ENOTSUP
|
|
|
|
# define EOPNOTSUPP ENOTSUP
|
|
|
|
# else
|
|
|
|
# define EOPNOTSUPP (-1)
|
|
|
|
# endif
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
|
|
|
#ifndef EPFNOSUPPORT
|
|
|
|
#define EPFNOSUPPORT (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EAFNOSUPPORT
|
|
|
|
#define EAFNOSUPPORT (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EADDRINUSE
|
|
|
|
#define EADDRINUSE (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EADDRNOTAVAIL
|
|
|
|
#define EADDRNOTAVAIL (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENETDOWN
|
|
|
|
#define ENETDOWN (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENETUNREACH
|
|
|
|
#define ENETUNREACH (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENETRESET
|
|
|
|
#define ENETRESET (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ECONNABORTED
|
|
|
|
#define ECONNABORTED (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ECONNRESET
|
|
|
|
#define ECONNRESET (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENOBUFS
|
|
|
|
#define ENOBUFS (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EISCONN
|
|
|
|
#define EISCONN (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENOTCONN
|
|
|
|
#define ENOTCONN (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ESHUTDOWN
|
|
|
|
#define ESHUTDOWN (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ETOOMANYREFS
|
|
|
|
#define ETOOMANYREFS (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ETIMEDOUT
|
|
|
|
#define ETIMEDOUT (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ECONNREFUSED
|
|
|
|
#define ECONNREFUSED (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EHOSTDOWN
|
|
|
|
#define EHOSTDOWN (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef EHOSTUNREACH
|
|
|
|
#define EHOSTUNREACH (-1)
|
|
|
|
#endif
|
|
|
|
#ifndef ENOTEMPTY
|
|
|
|
#define ENOTEMPTY (-1)
|
|
|
|
#endif
|
1996-04-12 08:57:28 -07:00
|
|
|
#ifndef ELOOP
|
|
|
|
#define ELOOP (-1)
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
2002-03-02 01:16:39 -08:00
|
|
|
#ifndef EOVERFLOW
|
|
|
|
#define EOVERFLOW (-1)
|
|
|
|
#endif
|
1995-05-08 08:18:32 -07:00
|
|
|
|
|
|
|
int error_table[] = {
|
1997-03-04 02:20:43 -08:00
|
|
|
E2BIG, EACCES, EAGAIN, EBADF, EBUSY, ECHILD, EDEADLK, EDOM,
|
1996-04-12 08:57:28 -07:00
|
|
|
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,
|
2002-03-02 01:16:39 -08:00
|
|
|
EHOSTUNREACH, ELOOP, EOVERFLOW /*, EUNKNOWNERR */
|
1995-05-08 08:18:32 -07:00
|
|
|
};
|
|
|
|
|
1996-11-08 06:47:07 -08:00
|
|
|
static value * unix_error_exn = NULL;
|
1995-05-08 08:18:32 -07:00
|
|
|
|
2005-09-06 05:38:32 -07:00
|
|
|
value unix_error_of_code (int errcode)
|
|
|
|
{
|
|
|
|
int errconstr;
|
|
|
|
value err;
|
|
|
|
|
2011-12-21 05:08:48 -08:00
|
|
|
#if defined(ENOTSUP) && (EOPNOTSUPP != ENOTSUP)
|
|
|
|
if (errcode == ENOTSUP)
|
|
|
|
errcode = EOPNOTSUPP;
|
|
|
|
#endif
|
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
errconstr =
|
2005-09-06 05:38:32 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void unix_error(int errcode, char *cmdname, value cmdarg)
|
1995-05-08 08:18:32 -07:00
|
|
|
{
|
|
|
|
value res;
|
1998-02-26 04:53:08 -08:00
|
|
|
value name = Val_unit, err = Val_unit, arg = Val_unit;
|
1997-05-26 10:16:31 -07:00
|
|
|
|
1998-02-26 04:53:08 -08:00
|
|
|
Begin_roots3 (name, err, arg);
|
|
|
|
arg = cmdarg == Nothing ? copy_string("") : cmdarg;
|
|
|
|
name = copy_string(cmdname);
|
2005-09-06 05:38:32 -07:00
|
|
|
err = unix_error_of_code (errcode);
|
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)
|
|
|
|
invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma");
|
|
|
|
}
|
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-02-26 04:53:08 -08:00
|
|
|
Field(res, 1) = err;
|
1997-05-26 10:16:31 -07:00
|
|
|
Field(res, 2) = name;
|
|
|
|
Field(res, 3) = arg;
|
|
|
|
End_roots();
|
1995-05-08 08:18:32 -07:00
|
|
|
mlraise(res);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void uerror(char *cmdname, value cmdarg)
|
1995-05-08 08:18:32 -07:00
|
|
|
{
|
|
|
|
unix_error(errno, cmdname, cmdarg);
|
|
|
|
}
|