Diff
Not logged in

Differences From Artifact [3f9020d7ee]:

To Artifact [594b5ac037]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * tclWinError.c --
 *
 *	This file contains code for converting from Win32 errors to errno
 *	errors.
 *
 * Copyright (c) 1995-1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclWinError.c,v 1.7.12.4 2008/12/10 21:20:18 davygrvy Exp $
 */

#include "tclInt.h"

/*
 * The following table contains the mapping from Win32 errors to errno errors.
 */











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * tclWinError.c --
 *
 *	This file contains code for converting from Win32 errors to errno
 *	errors.
 *
 * Copyright (c) 1995-1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclWinError.c,v 1.7.12.5 2008/12/12 05:26:52 davygrvy Exp $
 */

#include "tclInt.h"

/*
 * The following table contains the mapping from Win32 errors to errno errors.
 */
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304




305
306
307
308



309
310
311
312
313
314
315
316
317







318
319

320
321
322
323
324
325
326
    EINVAL,	/* 266 */
    ENOTDIR,	/* ERROR_DIRECTORY		267 */
};

static const unsigned int tableLen = sizeof(errorTable);

/*
 * The following tables contains the mapping from WinSock errors to
 * errno errors.
 */

static int wsaErrorTable1[] = {
    EINTR,		/* WSAEINTR	    Interrupted system call. */
    0,
    0,
    0,
    0,




    EBADF,		/* WSAEBADF	    Bad file number. */
    0,
    0,
    0,



    EACCES,		/* WSAEACCES	    Permission denied. */
    EFAULT,		/* WSAEFAULT	    Bad data address. */
    0,
    0,
    0,
    0,
    0,
    0,
    0,







    EINVAL,		/* WSAEINVAL	    Invalid argument. */
    0,

    EMFILE		/* WSAEMFILE	    Too many open files. */
};


static int wsaErrorTable2[] = {
    EWOULDBLOCK,	/* WSAEWOULDBLOCK   Operation would block. */
    EINPROGRESS,	/* WSAEINPROGRESS   Operation now in progress. */







|





<
<
<
<
>
>
>
>

<
<
<
>
>
>


<
<
<
<
<
<
<
>
>
>
>
>
>
>

<
>







288
289
290
291
292
293
294
295
296
297
298
299
300




301
302
303
304
305



306
307
308
309
310







311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326
    EINVAL,	/* 266 */
    ENOTDIR,	/* ERROR_DIRECTORY		267 */
};

static const unsigned int tableLen = sizeof(errorTable);

/*
 * The following tables contains the mapping from Winsock errors to
 * errno errors.
 */

static int wsaErrorTable1[] = {
    EINTR,		/* WSAEINTR	    Interrupted system call. */




    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EBADF,		/* WSAEBADF	    Bad file number. */



    EINVAL,
    EINVAL,
    EINVAL,
    EACCES,		/* WSAEACCES	    Permission denied. */
    EFAULT,		/* WSAEFAULT	    Bad data address. */







    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,		/* WSAEINVAL	    Invalid argument. */

    EINVAL,
    EMFILE		/* WSAEMFILE	    Too many open files. */
};


static int wsaErrorTable2[] = {
    EWOULDBLOCK,	/* WSAEWOULDBLOCK   Operation would block. */
    EINPROGRESS,	/* WSAEINPROGRESS   Operation now in progress. */
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381







382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
    ETOOMANYREFS,	/* WSAETOOMANYREFS  Too many references: cannot splice. */
    ETIMEDOUT,		/* WSAETIMEDOUT	    Connection timed out. */
    ECONNREFUSED,	/* WSAECONNREFUSED  Connection refused. */
    ELOOP,		/* WSAELOOP	    Too many levels of symbolic links. */
    ENAMETOOLONG,	/* WSAENAMETOOLONG  File name too long. */
    EHOSTDOWN,		/* WSAEHOSTDOWN	    Host is down. */
    EHOSTUNREACH,	/* WSAEHOSTUNREACH  No route to host. */
    ENOTEMPTY,		/* WSAENOTEMPTY	    Directory not empty. */
    EAGAIN,		/* WSAEPROCLIM	    Too many processes. */
    EUSERS,		/* WSAEUSERS	    Too many users. */
    EDQUOT,		/* WSAEDQUOT	    Ran out of disk quota. */
    ESTALE,		/* WSAESTALE	    File handle reference is no longer available. */
    EREMOTE,		/* WSAEREMOTE	    Item is not available locally. */
};

/*
 * These error codes are very windows specific and have no POSIX
 * translation, yet.
 *
 * TODO: Fixme!
 */

static int wsaErrorTable3[] = {
    EINVAL,		/* WSASYSNOTREADY	    WSAStartup cannot function at this time because the underlying system it uses to provide network services is currently unavailable. */
    EINVAL,		/* WSAVERNOTSUPPORTED	    The Windows Sockets version requested is not supported. */
    EINVAL,		/* WSANOTINITIALISED	    Either the application has not called WSAStartup, or WSAStartup failed. */
    0,
    0,
    0,
    0,
    0,
    0,
    0,







    ENOTCONN,		/* WSAEDISCON		    Returned by WSARecv or WSARecvFrom to indicate the remote party has initiated a graceful shutdown sequence. */
    EINVAL,		/* WSAENOMORE		    No more results can be returned by WSALookupServiceNext. */
    EINVAL,		/* WSAECANCELLED	    A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. */
    EINVAL,		/* WSAEINVALIDPROCTABLE	    The procedure call table is invalid. */
    EINVAL,		/* WSAEINVALIDPROVIDER	    The requested service provider is invalid. */
    EINVAL,		/* WSAEPROVIDERFAILEDINIT   The requested service provider could not be loaded or initialized. */
    EINVAL,		/* WSASYSCALLFAILURE	    A system call that should never fail has failed. */
    EINVAL,		/* WSASERVICE_NOT_FOUND	    No such service is known. The service cannot be found in the specified name space. */
    EINVAL,		/* WSATYPE_NOT_FOUND	    The specified class was not found. */
    EINVAL,		/* WSA_E_NO_MORE	    No more results can be returned by WSALookupServiceNext. */
    EINVAL,		/* WSA_E_CANCELLED	    A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. */
    EINVAL,		/* WSAEREFUSED		    A database query failed because it was actively refused. */
};

/*
 * These error codes are very windows specific and have no POSIX
 * translation, yet.

 *
 * TODO: Fixme!
 */

static int wsaErrorTable4[] = {
    EINVAL,	/* WSAHOST_NOT_FOUND,	Authoritative Answer: Host not found */
    EINVAL,	/* WSATRY_AGAIN,	Non-Authoritative: Host not found, or SERVERFAIL */
    EINVAL,	/* WSANO_RECOVERY,	Non-recoverable errors, FORMERR, REFUSED, NOTIMP */
    EINVAL,	/* WSANO_DATA,		Valid name, no data record of requested type */
    EINVAL,	/* WSA_QOS_RECEIVERS,		at least one Reserve has arrived */
    EINVAL,	/* WSA_QOS_SENDERS,		at least one Path has arrived */
    EINVAL,	/* WSA_QOS_NO_SENDERS,		there are no senders */
    EINVAL,	/* WSA_QOS_NO_RECEIVERS,	there are no receivers */
    EINVAL,	/* WSA_QOS_REQUEST_CONFIRMED,	Reserve has been confirmed */
    EINVAL,	/* WSA_QOS_ADMISSION_FAILURE,	error due to lack of resources */
    EINVAL,	/* WSA_QOS_POLICY_FAILURE,	rejected for administrative reasons - bad credentials */







|


















<
<
<
<
<
<
<
>
>
>
>
>
>
>
















|
>





|
|
|
|







349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374







375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    ETOOMANYREFS,	/* WSAETOOMANYREFS  Too many references: cannot splice. */
    ETIMEDOUT,		/* WSAETIMEDOUT	    Connection timed out. */
    ECONNREFUSED,	/* WSAECONNREFUSED  Connection refused. */
    ELOOP,		/* WSAELOOP	    Too many levels of symbolic links. */
    ENAMETOOLONG,	/* WSAENAMETOOLONG  File name too long. */
    EHOSTDOWN,		/* WSAEHOSTDOWN	    Host is down. */
    EHOSTUNREACH,	/* WSAEHOSTUNREACH  No route to host. */
    ENOTEMPTY,		/* WSAENOTEMPTY	    Directory is not empty. */
    EAGAIN,		/* WSAEPROCLIM	    Too many processes. */
    EUSERS,		/* WSAEUSERS	    Too many users. */
    EDQUOT,		/* WSAEDQUOT	    Ran out of disk quota. */
    ESTALE,		/* WSAESTALE	    File handle reference is no longer available. */
    EREMOTE,		/* WSAEREMOTE	    Item is not available locally. */
};

/*
 * These error codes are very windows specific and have no POSIX
 * translation, yet.
 *
 * TODO: Fixme!
 */

static int wsaErrorTable3[] = {
    EINVAL,		/* WSASYSNOTREADY	    WSAStartup cannot function at this time because the underlying system it uses to provide network services is currently unavailable. */
    EINVAL,		/* WSAVERNOTSUPPORTED	    The Windows Sockets version requested is not supported. */
    EINVAL,		/* WSANOTINITIALISED	    Either the application has not called WSAStartup, or WSAStartup failed. */







    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    EINVAL,
    ENOTCONN,		/* WSAEDISCON		    Returned by WSARecv or WSARecvFrom to indicate the remote party has initiated a graceful shutdown sequence. */
    EINVAL,		/* WSAENOMORE		    No more results can be returned by WSALookupServiceNext. */
    EINVAL,		/* WSAECANCELLED	    A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. */
    EINVAL,		/* WSAEINVALIDPROCTABLE	    The procedure call table is invalid. */
    EINVAL,		/* WSAEINVALIDPROVIDER	    The requested service provider is invalid. */
    EINVAL,		/* WSAEPROVIDERFAILEDINIT   The requested service provider could not be loaded or initialized. */
    EINVAL,		/* WSASYSCALLFAILURE	    A system call that should never fail has failed. */
    EINVAL,		/* WSASERVICE_NOT_FOUND	    No such service is known. The service cannot be found in the specified name space. */
    EINVAL,		/* WSATYPE_NOT_FOUND	    The specified class was not found. */
    EINVAL,		/* WSA_E_NO_MORE	    No more results can be returned by WSALookupServiceNext. */
    EINVAL,		/* WSA_E_CANCELLED	    A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. */
    EINVAL,		/* WSAEREFUSED		    A database query failed because it was actively refused. */
};

/*
 * These error codes are very windows specific and have no POSIX
 * translation.  Actually, the first four map to h_errno from BSD's
 * netdb.h, but h_errno has no map either to POSIX.  So we're stuck.
 *
 * TODO: Fixme!
 */

static int wsaErrorTable4[] = {
    EINVAL,	/* WSAHOST_NOT_FOUND,		Authoritative Answer: Host not found */
    EINVAL,	/* WSATRY_AGAIN,		Non-Authoritative: Host not found, or SERVERFAIL */
    EINVAL,	/* WSANO_RECOVERY,		Non-recoverable errors, FORMERR, REFUSED, NOTIMP */
    EINVAL,	/* WSANO_DATA,			Valid name, no data record of requested type */
    EINVAL,	/* WSA_QOS_RECEIVERS,		at least one Reserve has arrived */
    EINVAL,	/* WSA_QOS_SENDERS,		at least one Path has arrived */
    EINVAL,	/* WSA_QOS_NO_SENDERS,		there are no senders */
    EINVAL,	/* WSA_QOS_NO_RECEIVERS,	there are no receivers */
    EINVAL,	/* WSA_QOS_REQUEST_CONFIRMED,	Reserve has been confirmed */
    EINVAL,	/* WSA_QOS_ADMISSION_FAILURE,	error due to lack of resources */
    EINVAL,	/* WSA_QOS_POLICY_FAILURE,	rejected for administrative reasons - bad credentials */
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

444
445
446
447
448
449

450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
    EINVAL,	/* WSA_QOS_EFLOWDESC,		invalid flow descriptor in the list */
    EINVAL,	/* WSA_QOS_EPSFLOWSPEC,		inconsistent flow spec in provider specific buffer */
    EINVAL,	/* WSA_QOS_EPSFILTERSPEC,	invalid filter spec in provider specific buffer */
    EINVAL,	/* WSA_QOS_ESDMODEOBJ,		invalid shape discard mode object in provider specific buffer */
    EINVAL,	/* WSA_QOS_ESHAPERATEOBJ,	invalid shaping rate object in provider specific buffer */
    EINVAL,	/* WSA_QOS_RESERVED_PETYPE,	reserved policy element in provider specific buffer */
};


/*
 *----------------------------------------------------------------------
 *
 * TclWinConvertError --
 *
 *	This routine converts a Win32 error into an errno value.

 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the errno global variable.

 *
 *----------------------------------------------------------------------
 */

void
TclWinConvertError(
    DWORD errCode)		/* Win32 error code. */
{
    if (errCode >= tableLen) {
	Tcl_SetErrno(EINVAL);
    } else {
	Tcl_SetErrno(errorTable[errCode]);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TclWinConvertWSAError --
 *
 *	This routine converts a WinSock error into an errno value.

 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the errno global variable.

 *
 *----------------------------------------------------------------------
 */

void
TclWinConvertWSAError(
    DWORD errCode)		/* Win32 error code. */
{
    if ((errCode >= WSAEINTR) && (errCode <= WSAEMFILE)) {
	Tcl_SetErrno(wsaErrorTable1[errCode - WSAEINTR]);
    } else if ((errCode >= WSAEWOULDBLOCK) && (errCode <= WSAEREMOTE)) {
	Tcl_SetErrno(wsaErrorTable2[errCode - WSAEWOULDBLOCK]);
    } else if ((errCode >= WSASYSNOTREADY) && (errCode <= WSAEREFUSED)) {
	Tcl_SetErrno(wsaErrorTable3[errCode - WSASYSNOTREADY]);
    } else if ((errCode >= WSAHOST_NOT_FOUND) && (errCode <= WSA_QOS_RESERVED_PETYPE)) {
	Tcl_SetErrno(wsaErrorTable4[errCode - WSAHOST_NOT_FOUND]);
    } else {
	Tcl_SetErrno(EINVAL);
    }
}







<






|
>





|
>




















|
>





|
>






|













430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
    EINVAL,	/* WSA_QOS_EFLOWDESC,		invalid flow descriptor in the list */
    EINVAL,	/* WSA_QOS_EPSFLOWSPEC,		inconsistent flow spec in provider specific buffer */
    EINVAL,	/* WSA_QOS_EPSFILTERSPEC,	invalid filter spec in provider specific buffer */
    EINVAL,	/* WSA_QOS_ESDMODEOBJ,		invalid shape discard mode object in provider specific buffer */
    EINVAL,	/* WSA_QOS_ESHAPERATEOBJ,	invalid shaping rate object in provider specific buffer */
    EINVAL,	/* WSA_QOS_RESERVED_PETYPE,	reserved policy element in provider specific buffer */
};


/*
 *----------------------------------------------------------------------
 *
 * TclWinConvertError --
 *
 *	This routine converts a Win32 error into an errno value
 *	if the conversion is possible, else EINVAL.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the errno global variable.  Doesn't translate well
 *	and results in some info loss.
 *
 *----------------------------------------------------------------------
 */

void
TclWinConvertError(
    DWORD errCode)		/* Win32 error code. */
{
    if (errCode >= tableLen) {
	Tcl_SetErrno(EINVAL);
    } else {
	Tcl_SetErrno(errorTable[errCode]);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TclWinConvertWSAError --
 *
 *	This routine converts a WinSock error into a POSIX errno value
 *	if the conversion is possible, else EINVAL.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the errno global variable.  Doesn't translate well
 *	and results in some info loss.
 *
 *----------------------------------------------------------------------
 */

void
TclWinConvertWSAError(
    DWORD errCode)		/* Winsock error code. */
{
    if ((errCode >= WSAEINTR) && (errCode <= WSAEMFILE)) {
	Tcl_SetErrno(wsaErrorTable1[errCode - WSAEINTR]);
    } else if ((errCode >= WSAEWOULDBLOCK) && (errCode <= WSAEREMOTE)) {
	Tcl_SetErrno(wsaErrorTable2[errCode - WSAEWOULDBLOCK]);
    } else if ((errCode >= WSASYSNOTREADY) && (errCode <= WSAEREFUSED)) {
	Tcl_SetErrno(wsaErrorTable3[errCode - WSASYSNOTREADY]);
    } else if ((errCode >= WSAHOST_NOT_FOUND) && (errCode <= WSA_QOS_RESERVED_PETYPE)) {
	Tcl_SetErrno(wsaErrorTable4[errCode - WSAHOST_NOT_FOUND]);
    } else {
	Tcl_SetErrno(EINVAL);
    }
}