Diff
Not logged in

Differences From Artifact [17794a8a93]:

To Artifact [e43856f896]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
11
12
13









14
15
16
17
18
19
20













-
-
-
-
-
-
-
-
-







/*
 * 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.
 */

#include "tclInt.h"

#ifndef WSAEWOULDBLOCK
#   define WSAEWOULDBLOCK 10035L
#endif

#ifndef __WIN32__
#   define DWORD unsigned int
#endif

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

static const unsigned char errorTable[] = {
    0,
    EINVAL,	/* ERROR_INVALID_FUNCTION	1 */
336
337
338
339
340
341
342





343
344
345
346
347
348
349
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345







+
+
+
+
+







    EAGAIN,		/* WSAEPROCLIM */
    EUSERS,		/* WSAEUSERS */
    EDQUOT,		/* WSAEDQUOT */
    ESTALE,		/* WSAESTALE */
    EREMOTE		/* WSAEREMOTE */
};

#ifdef __CYGWIN__
#   include <windows.h>
#   define DWORD unsigned int
#endif

/*
 *----------------------------------------------------------------------
 *
 * TclWinConvertError --
 *
 *	This routine converts a Win32 error into an errno value.
 *
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
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

416
417
418

419
420
421
422
423
424
425
426
427







+
+
-
+
+
+
+




-
+
+



-
+

-
+
+





-
+





-
-
+
+

+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
+


-
+








 */

void
TclWinConvertError(
    DWORD errCode)		/* Win32 error code. */
{
    if (errCode >= sizeof(errorTable)/sizeof(errorTable[0])) {
	errCode -= WSAEWOULDBLOCK;
	if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) {
	Tcl_SetErrno(EINVAL);
	    Tcl_SetErrno(errorTable[1]);
	} else {
	    Tcl_SetErrno(wsaErrorTable[errCode]);
	}
    } else {
	Tcl_SetErrno(errorTable[errCode]);
    }
}


#ifdef __CYGWIN__
/*
 *----------------------------------------------------------------------
 *
 * TclWinConvertWSAError --
 * tclWinDebugPanic --
 *
 *	This routine converts a WinSock error into an errno value.
 *	Display a message. If a debugger is present, present it directly to
 *	the debugger, otherwise send it to stderr.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the errno global variable.
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TclWinConvertWSAError(
    DWORD errCode)		/* Win32 error code. */
tclWinDebugPanic(
    const char *format, ...)
{
#define TCL_MAX_WARN_LEN 1024
    va_list argList;
    va_start(argList, format);
    errCode -= WSAEWOULDBLOCK;
    if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) {
	Tcl_SetErrno(EINVAL);

    if (IsDebuggerPresent()) {
	WCHAR msgString[TCL_MAX_WARN_LEN];
	char buf[TCL_MAX_WARN_LEN * TCL_UTF_MAX];

	vsnprintf(buf, sizeof(buf), format, argList);
	msgString[TCL_MAX_WARN_LEN-1] = L'\0';
	MultiByteToWideChar(CP_UTF8, 0, buf, -1, msgString, TCL_MAX_WARN_LEN);

	/*
	 * Truncate MessageBox string if it is too long to not overflow the buffer.
	 */

	if (msgString[TCL_MAX_WARN_LEN-1] != L'\0') {
	    memcpy(msgString + (TCL_MAX_WARN_LEN - 5), L" ...", 5 * sizeof(WCHAR));
	}
	OutputDebugStringW(msgString);
    } else {
	vfprintf(stderr, format, argList);
	fprintf(stderr, "\n");
	Tcl_SetErrno(wsaErrorTable[errCode]);
	fflush(stderr);
    }
}

#endif
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * tab-width: 8
 * End:
 */