1 /***********************************************************************/
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../../LICENSE. */
12 /***********************************************************************/
14 /* $Id: unixsupport.c 7045 2005-09-06 12:38:32Z doligez $ */
21 #include "unixsupport.h"
22 #include "cst2constr.h"
78 #define ENAMETOOLONG (-1)
108 #define ENOTEMPTY (-1)
138 #define EWOULDBLOCK (-1)
141 #define EINPROGRESS (-1)
144 #define EALREADY (-1)
147 #define ENOTSOCK (-1)
150 #define EDESTADDRREQ (-1)
153 #define EMSGSIZE (-1)
156 #define EPROTOTYPE (-1)
159 #define ENOPROTOOPT (-1)
161 #ifndef EPROTONOSUPPORT
162 #define EPROTONOSUPPORT (-1)
164 #ifndef ESOCKTNOSUPPORT
165 #define ESOCKTNOSUPPORT (-1)
168 #define EOPNOTSUPP (-1)
171 #define EPFNOSUPPORT (-1)
174 #define EAFNOSUPPORT (-1)
177 #define EADDRINUSE (-1)
179 #ifndef EADDRNOTAVAIL
180 #define EADDRNOTAVAIL (-1)
183 #define ENETDOWN (-1)
186 #define ENETUNREACH (-1)
189 #define ENETRESET (-1)
192 #define ECONNABORTED (-1)
195 #define ECONNRESET (-1)
204 #define ENOTCONN (-1)
207 #define ESHUTDOWN (-1)
210 #define ETOOMANYREFS (-1)
213 #define ETIMEDOUT (-1)
216 #define ECONNREFUSED (-1)
219 #define EHOSTDOWN (-1)
222 #define EHOSTUNREACH (-1)
225 #define ENOTEMPTY (-1)
231 #define EOVERFLOW (-1)
234 int error_table[] = {
235 E2BIG, EACCES, EAGAIN, EBADF, EBUSY, ECHILD, EDEADLK, EDOM,
236 EEXIST, EFAULT, EFBIG, EINTR, EINVAL, EIO, EISDIR, EMFILE, EMLINK,
237 ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOEXEC, ENOLCK, ENOMEM, ENOSPC,
238 ENOSYS, ENOTDIR, ENOTEMPTY, ENOTTY, ENXIO, EPERM, EPIPE, ERANGE,
239 EROFS, ESPIPE, ESRCH, EXDEV, EWOULDBLOCK, EINPROGRESS, EALREADY,
240 ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT,
241 EPROTONOSUPPORT, ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT,
242 EAFNOSUPPORT, EADDRINUSE, EADDRNOTAVAIL, ENETDOWN, ENETUNREACH,
243 ENETRESET, ECONNABORTED, ECONNRESET, ENOBUFS, EISCONN, ENOTCONN,
244 ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, EHOSTDOWN,
245 EHOSTUNREACH, ELOOP, EOVERFLOW /*, EUNKNOWNERR */
248 static value * unix_error_exn = NULL;
250 value unix_error_of_code (int errcode)
256 cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1);
257 if (errconstr == Val_int(-1)) {
258 err = alloc_small(1, 0);
259 Field(err, 0) = Val_int(errcode);
266 void unix_error(int errcode, char *cmdname, value cmdarg)
269 value name = Val_unit, err = Val_unit, arg = Val_unit;
271 Begin_roots3 (name, err, arg);
272 arg = cmdarg == Nothing ? copy_string("") : cmdarg;
273 name = copy_string(cmdname);
274 err = unix_error_of_code (errcode);
275 if (unix_error_exn == NULL) {
276 unix_error_exn = caml_named_value("Unix.Unix_error");
277 if (unix_error_exn == NULL)
278 invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma");
280 res = alloc_small(4, 0);
281 Field(res, 0) = *unix_error_exn;
283 Field(res, 2) = name;
289 void uerror(char *cmdname, value cmdarg)
291 unix_error(errno, cmdname, cmdarg);