summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclFCmd.c8
-rw-r--r--macosx/tclMacOSXFCmd.c3
-rw-r--r--unix/tclUnixChan.c21
-rw-r--r--unix/tclUnixFCmd.c5
-rw-r--r--win/tclWinChan.c2
-rw-r--r--win/tclWinDde.c16
-rw-r--r--win/tclWinFCmd.c5
-rw-r--r--win/tclWinLoad.c27
-rw-r--r--win/tclWinPipe.c2
-rw-r--r--win/tclWinReg.c2
-rw-r--r--win/tclWinSerial.c65
-rw-r--r--win/tclWinSock.c90
12 files changed, 173 insertions, 73 deletions
diff --git a/generic/tclFCmd.c b/generic/tclFCmd.c
index c3a0a5e..e9176ca 100644
--- a/generic/tclFCmd.c
+++ b/generic/tclFCmd.c
@@ -1060,6 +1060,7 @@ TclFileAttrsCmd(
Tcl_AppendResult(interp, "bad option \"", TclGetString(objv[0]),
"\", there are no file attributes in this filesystem.",
NULL);
+ Tcl_SetErrorCode(interp, "TCL","OPERATION","FATTR","NONE", NULL);
goto end;
}
@@ -1086,6 +1087,7 @@ TclFileAttrsCmd(
Tcl_AppendResult(interp, "bad option \"", TclGetString(objv[0]),
"\", there are no file attributes in this filesystem.",
NULL);
+ Tcl_SetErrorCode(interp, "TCL","OPERATION","FATTR","NONE", NULL);
goto end;
}
@@ -1100,6 +1102,8 @@ TclFileAttrsCmd(
if (i + 1 == objc) {
Tcl_AppendResult(interp, "value for \"",
TclGetString(objv[i]), "\" missing", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FATTR",
+ "NOVALUE", NULL);
goto end;
}
if (Tcl_FSFileAttrsSet(interp, index, filePtr,
@@ -1213,6 +1217,7 @@ TclFileLinkCmd(
Tcl_AppendResult(interp, "could not create new link \"",
TclGetString(objv[index]),
"\": that path already exists", NULL);
+ Tcl_PosixError(interp);
} else if (errno == ENOENT) {
/*
* There are two cases here: either the target doesn't exist,
@@ -1232,11 +1237,14 @@ TclFileLinkCmd(
Tcl_AppendResult(interp, "could not create new link \"",
TclGetString(objv[index]),
"\": no such file or directory", NULL);
+ Tcl_PosixError(interp);
} else {
Tcl_AppendResult(interp, "could not create new link \"",
TclGetString(objv[index]), "\": target \"",
TclGetString(objv[index+1]), "\" doesn't exist",
NULL);
+ errno = ENOENT;
+ Tcl_PosixError(interp);
}
} else {
Tcl_AppendResult(interp, "could not create new link \"",
diff --git a/macosx/tclMacOSXFCmd.c b/macosx/tclMacOSXFCmd.c
index 717c947..64cbbea 100644
--- a/macosx/tclMacOSXFCmd.c
+++ b/macosx/tclMacOSXFCmd.c
@@ -200,6 +200,7 @@ TclMacOSXGetFileAttribute(
return TCL_OK;
#else
Tcl_AppendResult(interp, "Mac OS X file attributes not supported", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "UNSUPPORTED", NULL);
return TCL_ERROR;
#endif
}
@@ -329,6 +330,7 @@ TclMacOSXSetFileAttribute(
if (newRsrcForkSize != 0) {
Tcl_AppendResult(interp,
"setting nonzero rsrclength not supported", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "UNSUPPORTED", NULL);
return TCL_ERROR;
}
@@ -369,6 +371,7 @@ TclMacOSXSetFileAttribute(
return TCL_OK;
#else
Tcl_AppendResult(interp, "Mac OS X file attributes not supported", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "UNSUPPORTED", NULL);
return TCL_ERROR;
#endif
}
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c
index 6ee9b89..866d77d 100644
--- a/unix/tclUnixChan.c
+++ b/unix/tclUnixChan.c
@@ -139,6 +139,7 @@ typedef struct TtyAttrs {
if (interp) { \
Tcl_AppendResult(interp, (detail), \
" not supported for this platform", NULL); \
+ Tcl_SetErrorCode(interp, "TCL", "UNSUPPORTED", NULL); \
}
/*
@@ -699,6 +700,8 @@ TtySetOptionProc(
Tcl_AppendResult(interp, "bad value for -handshake: "
"must be one of xonxoff, rtscts, dtrdsr or none",
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
+ "VALUE", NULL);
}
return TCL_ERROR;
}
@@ -719,6 +722,8 @@ TtySetOptionProc(
if (interp) {
Tcl_AppendResult(interp, "bad value for -xchar: "
"should be a list of two elements", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
+ "VALUE", NULL);
}
ckfree(argv);
return TCL_ERROR;
@@ -770,6 +775,8 @@ TtySetOptionProc(
if (interp) {
Tcl_AppendResult(interp, "bad value for -ttycontrol: "
"should be a list of signal,value pairs", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
+ "VALUE", NULL);
}
ckfree(argv);
return TCL_ERROR;
@@ -818,6 +825,8 @@ TtySetOptionProc(
Tcl_AppendResult(interp, "bad signal \"", argv[i],
"\" for -ttycontrol: must be "
"DTR, RTS or BREAK", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
+ "VALUE", NULL);
}
ckfree(argv);
return TCL_ERROR;
@@ -1381,6 +1390,7 @@ TtyParseMode(
if (interp != NULL) {
Tcl_AppendResult(interp, bad, ": should be baud,parity,data,stop",
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
}
@@ -1409,6 +1419,7 @@ TtyParseMode(
"n, o, or e",
#endif /* PAREXT|USE_TERMIO */
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
}
@@ -1417,12 +1428,14 @@ TtyParseMode(
if (interp != NULL) {
Tcl_AppendResult(interp, bad, " data: should be 5, 6, 7, or 8",
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
}
if ((*stopPtr < 0) || (*stopPtr > 2)) {
if (interp != NULL) {
Tcl_AppendResult(interp, bad, " stop: should be 1 or 2", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
}
@@ -1832,10 +1845,14 @@ Tcl_GetOpenFile(
if ((forWriting) && ((chanMode & TCL_WRITABLE) == 0)) {
Tcl_AppendResult(interp, "\"", chanID, "\" wasn't opened for writing",
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_WRITABLE",
+ NULL);
return TCL_ERROR;
} else if ((!forWriting) && ((chanMode & TCL_READABLE) == 0)) {
Tcl_AppendResult(interp, "\"", chanID, "\" wasn't opened for reading",
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_READABLE",
+ NULL);
return TCL_ERROR;
}
@@ -1866,6 +1883,8 @@ Tcl_GetOpenFile(
if (f == NULL) {
Tcl_AppendResult(interp, "cannot get a FILE * for \"", chanID,
"\"", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL",
+ "FILE_FAILURE", NULL);
return TCL_ERROR;
}
*filePtr = f;
@@ -1875,6 +1894,8 @@ Tcl_GetOpenFile(
Tcl_AppendResult(interp, "\"", chanID,
"\" cannot be used to get a FILE *", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NO_DESCRIPTOR",
+ NULL);
return TCL_ERROR;
}
diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c
index c71ccd0..e3d9022 100644
--- a/unix/tclUnixFCmd.c
+++ b/unix/tclUnixFCmd.c
@@ -1483,6 +1483,8 @@ SetGroupAttribute(
Tcl_AppendResult(interp, "could not set group for file \"",
TclGetString(fileName), "\": group \"", string,
"\" does not exist", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "SETGRP",
+ "NO_GROUP", NULL);
}
return TCL_ERROR;
}
@@ -1547,6 +1549,8 @@ SetOwnerAttribute(
Tcl_AppendResult(interp, "could not set owner for file \"",
TclGetString(fileName), "\": user \"", string,
"\" does not exist", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "SETOWN",
+ "NO_USER", NULL);
}
return TCL_ERROR;
}
@@ -1640,6 +1644,7 @@ SetPermissionsAttribute(
if (interp != NULL) {
Tcl_AppendResult(interp, "unknown permission string format \"",
modeStringPtr, "\"", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "PERMISSION", NULL);
}
return TCL_ERROR;
}
diff --git a/win/tclWinChan.c b/win/tclWinChan.c
index 6e1844b..517aa20 100644
--- a/win/tclWinChan.c
+++ b/win/tclWinChan.c
@@ -997,6 +997,8 @@ TclpOpenFileChannel(
channel = NULL;
Tcl_AppendResult(interp, "couldn't open \"", TclGetString(pathPtr),
"\": bad file type", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "BAD_TYPE",
+ NULL);
break;
}
diff --git a/win/tclWinDde.c b/win/tclWinDde.c
index 75f4345..6523357 100644
--- a/win/tclWinDde.c
+++ b/win/tclWinDde.c
@@ -531,6 +531,7 @@ ExecuteRemoteObject(
Tcl_SetObjResult(riPtr->interp, Tcl_NewStringObj("permission denied: "
"a handler procedure must be defined for use in a safe "
"interp", -1));
+ Tcl_SetErrorCode(riPtr->interp, "TCL", "DDE", "SECURITY_CHECK", NULL);
result = TCL_ERROR;
}
@@ -898,6 +899,7 @@ MakeDdeConnection(
if (interp != NULL) {
Tcl_AppendResult(interp, "no registered server named \"",
name, "\"", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "DDE", "NO_SERVER", NULL);
}
return TCL_ERROR;
}
@@ -1100,25 +1102,30 @@ static void
SetDdeError(
Tcl_Interp *interp) /* The interp to put the message in. */
{
- const char *errorMessage;
+ const char *errorMessage, *errorCode;
switch (DdeGetLastError(ddeInstance)) {
case DMLERR_DATAACKTIMEOUT:
case DMLERR_EXECACKTIMEOUT:
case DMLERR_POKEACKTIMEOUT:
errorMessage = "remote interpreter did not respond";
+ errorCode = "TIMEOUT";
break;
case DMLERR_BUSY:
errorMessage = "remote server is busy";
+ errorCode = "BUSY";
break;
case DMLERR_NOTPROCESSED:
errorMessage = "remote server cannot handle this command";
+ errorCode = "NOCANDO";
break;
default:
errorMessage = "dde command failed";
+ errorCode = "FAILED";
}
Tcl_SetObjResult(interp, Tcl_NewStringObj(errorMessage, -1));
+ Tcl_SetErrorCode(interp, "TCL", "DDE", errorCode, NULL);
}
/*
@@ -1355,6 +1362,7 @@ DdeObjCmd(
if (dataLength == 0) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("cannot execute null data", -1));
+ Tcl_SetErrorCode(interp, "TCL", "DDE", "NULL", NULL);
result = TCL_ERROR;
break;
}
@@ -1397,6 +1405,7 @@ DdeObjCmd(
if (length == 0) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("cannot request value of null data", -1));
+ Tcl_SetErrorCode(interp, "TCL", "DDE", "NULL", NULL);
result = TCL_ERROR;
goto cleanup;
}
@@ -1447,6 +1456,7 @@ DdeObjCmd(
if (length == 0) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("cannot have a null item", -1));
+ Tcl_SetErrorCode(interp, "TCL", "DDE", "NULL", NULL);
result = TCL_ERROR;
goto cleanup;
}
@@ -1489,6 +1499,7 @@ DdeObjCmd(
if (serviceName == NULL) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("invalid service name \"\"", -1));
+ Tcl_SetErrorCode(interp, "TCL", "DDE", "NO_SERVER", NULL);
result = TCL_ERROR;
goto cleanup;
}
@@ -1536,6 +1547,8 @@ DdeObjCmd(
Tcl_SetResult(riPtr->interp, "permission denied: "
"a handler procedure must be defined for use in "
"a safe interp", TCL_STATIC);
+ Tcl_SetErrorCode(interp, "TCL", "DDE", "SECURITY_CHECK",
+ NULL);
result = TCL_ERROR;
}
@@ -1600,6 +1613,7 @@ DdeObjCmd(
Tcl_SetObjResult(interp,
Tcl_NewStringObj("invalid data returned from server",
-1));
+ Tcl_SetErrorCode(interp, "TCL", "DDE", "BAD_RESPONSE", NULL);
result = TCL_ERROR;
goto cleanup;
}
diff --git a/win/tclWinFCmd.c b/win/tclWinFCmd.c
index 07abc83..fea9ddb 100644
--- a/win/tclWinFCmd.c
+++ b/win/tclWinFCmd.c
@@ -1653,6 +1653,8 @@ ConvertFileNameFormat(
Tcl_AppendResult(interp, "could not read \"",
Tcl_GetString(fileName), "\": no such file or directory",
(char *) NULL);
+ errno = ENOENT;
+ Tcl_PosixError(interp);
}
goto cleanup;
}
@@ -1944,9 +1946,10 @@ CannotSetAttribute(
Tcl_AppendResult(interp, "cannot set attribute \"",
tclpFileAttrStrings[objIndex], "\" for file \"",
Tcl_GetString(fileName), "\": attribute is readonly", NULL);
+ errno = EINVAL;
+ Tcl_PosixError(interp);
return TCL_ERROR;
}
-
/*
*---------------------------------------------------------------------------
diff --git a/win/tclWinLoad.c b/win/tclWinLoad.c
index e877ebe..3f4d4d9 100644
--- a/win/tclWinLoad.c
+++ b/win/tclWinLoad.c
@@ -125,20 +125,27 @@ TclpDlopen(
switch (lastError) {
case ERROR_MOD_NOT_FOUND:
+ Tcl_SetErrorCode(interp, "WIN_LOAD", "MOD_NOT_FOUND", NULL);
+ goto notFoundMsg;
case ERROR_DLL_NOT_FOUND:
+ Tcl_SetErrorCode(interp, "WIN_LOAD", "DLL_NOT_FOUND", NULL);
+ notFoundMsg:
Tcl_AppendResult(interp, "this library or a dependent library"
" could not be found in library path", NULL);
break;
case ERROR_PROC_NOT_FOUND:
+ Tcl_SetErrorCode(interp, "WIN_LOAD", "PROC_NOT_FOUND", NULL);
Tcl_AppendResult(interp, "A function specified in the import"
" table could not be resolved by the system. Windows"
" is not telling which one, I'm sorry.", NULL);
break;
case ERROR_INVALID_DLL:
+ Tcl_SetErrorCode(interp, "WIN_LOAD", "INVALID_DLL", NULL);
Tcl_AppendResult(interp, "this library or a dependent library"
" is damaged", NULL);
break;
case ERROR_DLL_INIT_FAILED:
+ Tcl_SetErrorCode(interp, "WIN_LOAD", "DLL_INIT_FAILED", NULL);
Tcl_AppendResult(interp, "the library initialization"
" routine failed", NULL);
break;
@@ -147,14 +154,18 @@ TclpDlopen(
Tcl_AppendResult(interp, Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
- } else {
- handlePtr = ckalloc(sizeof(struct Tcl_LoadHandle_));
- handlePtr->clientData = (ClientData) hInstance;
- handlePtr->findSymbolProcPtr = &FindSymbol;
- handlePtr->unloadFileProcPtr = &UnloadFile;
- *loadHandle = handlePtr;
- *unloadProcPtr = &UnloadFile;
}
+
+ /*
+ * Succeded; package everything up for Tcl.
+ */
+
+ handlePtr = ckalloc(sizeof(struct Tcl_LoadHandle_));
+ handlePtr->clientData = (ClientData) hInstance;
+ handlePtr->findSymbolProcPtr = &FindSymbol;
+ handlePtr->unloadFileProcPtr = &UnloadFile;
+ *loadHandle = handlePtr;
+ *unloadProcPtr = &UnloadFile;
return TCL_OK;
}
@@ -344,7 +355,7 @@ TclpTempFileNameForLibrary(Tcl_Interp* interp, /* Tcl interpreter */
}
if (dllDirectoryName == NULL) {
Tcl_AppendResult(interp, "couldn't create temporary directory: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_PosixError(interp), NULL);
}
fileName = TclpNativeToNormalized(dllDirectoryName);
tail = TclPathPart(interp, path, TCL_PATH_TAIL);
diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c
index 74021e9..b9b881c 100644
--- a/win/tclWinPipe.c
+++ b/win/tclWinPipe.c
@@ -1136,6 +1136,8 @@ TclpCreateProcess(
Tcl_AppendResult(interp,
"DOS application process not supported on this platform",
(char *) NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "EXEC", "DOS_APP",
+ NULL);
goto end;
}
}
diff --git a/win/tclWinReg.c b/win/tclWinReg.c
index 7462031..1390415 100644
--- a/win/tclWinReg.c
+++ b/win/tclWinReg.c
@@ -421,6 +421,7 @@ DeleteKey(
if (*keyName == '\0') {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("bad key: cannot delete root keys", -1));
+ Tcl_SetErrorCode(interp, "WIN_REG", "DEL_ROOT_KEY", NULL);
ckfree(buffer);
return TCL_ERROR;
}
@@ -1123,6 +1124,7 @@ ParseKeyName(
if (!rootName) {
Tcl_AppendResult(interp, "bad key \"", name,
"\": must start with a valid root", NULL);
+ Tcl_SetErrorCode(interp, "WIN_REG", "NO_ROOT_KEY", NULL);
return TCL_ERROR;
}
diff --git a/win/tclWinSerial.c b/win/tclWinSerial.c
index 2bcc77c..503358b 100644
--- a/win/tclWinSerial.c
+++ b/win/tclWinSerial.c
@@ -1676,7 +1676,9 @@ SerialSetOptionProc(
if ((len > 2) && (strncmp(optionName, "-mode", len) == 0)) {
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't get comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't get comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1688,6 +1690,7 @@ SerialSetOptionProc(
if (interp != NULL) {
Tcl_AppendResult(interp, "bad value \"", value,
"\" for -mode: should be baud,parity,data,stop", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
}
@@ -1703,7 +1706,9 @@ SerialSetOptionProc(
if (!SetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't set comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't set comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1717,7 +1722,9 @@ SerialSetOptionProc(
if ((len > 1) && (strncmp(optionName, "-handshake", len) == 0)) {
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't get comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't get comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1757,13 +1764,16 @@ SerialSetOptionProc(
Tcl_AppendResult(interp, "bad value \"", value,
"\" for -handshake: must be one of xonxoff, rtscts, "
"dtrdsr or none", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "HANDSHAKE", NULL);
}
return TCL_ERROR;
}
if (!SetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't set comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't set comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1777,7 +1787,9 @@ SerialSetOptionProc(
if ((len > 1) && (strncmp(optionName, "-xchar", len) == 0)) {
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't get comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't get comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1791,6 +1803,7 @@ SerialSetOptionProc(
Tcl_AppendResult(interp, "bad value for -xchar: should be "
"a list of two elements with each a single character",
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "XCHAR", NULL);
}
ckfree(argv);
return TCL_ERROR;
@@ -1827,7 +1840,9 @@ SerialSetOptionProc(
if (!SetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't set comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't set comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1849,6 +1864,7 @@ SerialSetOptionProc(
Tcl_AppendResult(interp, "bad value \"", value,
"\" for -ttycontrol: should be a list of "
"signal,value pairs", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "TTYCONTROL", NULL);
}
ckfree(argv);
return TCL_ERROR;
@@ -1864,6 +1880,8 @@ SerialSetOptionProc(
(DWORD) (flag ? SETDTR : CLRDTR))) {
if (interp != NULL) {
Tcl_AppendResult(interp, "can't set DTR signal", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION",
+ "FCONFIGURE", "TTY_SIGNAL", NULL);
}
result = TCL_ERROR;
break;
@@ -1873,6 +1891,8 @@ SerialSetOptionProc(
(DWORD) (flag ? SETRTS : CLRRTS))) {
if (interp != NULL) {
Tcl_AppendResult(interp, "can't set RTS signal", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION",
+ "FCONFIGURE", "TTY_SIGNAL", NULL);
}
result = TCL_ERROR;
break;
@@ -1882,6 +1902,8 @@ SerialSetOptionProc(
(DWORD) (flag ? SETBREAK : CLRBREAK))) {
if (interp != NULL) {
Tcl_AppendResult(interp,"can't set BREAK signal",NULL);
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION",
+ "FCONFIGURE", "TTY_SIGNAL", NULL);
}
result = TCL_ERROR;
break;
@@ -1891,6 +1913,8 @@ SerialSetOptionProc(
Tcl_AppendResult(interp, "bad signal name \"", argv[i],
"\" for -ttycontrol: must be DTR, RTS or BREAK",
NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "TTY_SIGNAL",
+ NULL);
}
result = TCL_ERROR;
break;
@@ -1930,13 +1954,16 @@ SerialSetOptionProc(
Tcl_AppendResult(interp, "bad value \"", value,
"\" for -sysbuffer: should be a list of one or two "
"integers > 0", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "SYS_BUFFER", NULL);
}
return TCL_ERROR;
}
if (!SetupComm(infoPtr->handle, inSize, outSize)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't setup comm buffers", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't setup comm buffers: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1950,7 +1977,9 @@ SerialSetOptionProc(
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't get comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't get comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1958,7 +1987,9 @@ SerialSetOptionProc(
dcb.XoffLim = (WORD) (infoPtr->sysBufRead*1/4);
if (!SetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't set comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't set comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -1990,7 +2021,9 @@ SerialSetOptionProc(
tout.ReadTotalTimeoutConstant = msec;
if (!SetCommTimeouts(infoPtr->handle, &tout)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't set comm timeouts", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't set comm timeouts: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -2057,7 +2090,9 @@ SerialGetOptionProc(
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't get comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't get comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -2125,7 +2160,9 @@ SerialGetOptionProc(
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't get comm state", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't get comm state: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -2201,7 +2238,9 @@ SerialGetOptionProc(
if (!GetCommModemStatus(infoPtr->handle, &status)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "can't get tty status", NULL);
+ TclWinConvertError(GetLastError());
+ Tcl_AppendResult(interp, "can't get tty status: ",
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index bd5f0f4..4134420 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -287,8 +287,7 @@ InitSockets(void)
DWORD id;
WSADATA wsaData;
DWORD err;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- TclThreadDataKeyGet(&dataKey);
+ ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
if (!initialized) {
initialized = 1;
@@ -482,9 +481,8 @@ SocketExitHandler(
void
TclpFinalizeSockets(void)
{
- ThreadSpecificData *tsdPtr;
+ ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
- tsdPtr = (ThreadSpecificData *) TclThreadDataKeyGet(&dataKey);
if (tsdPtr != NULL) {
if (tsdPtr->socketThread != NULL) {
if (tsdPtr->hwnd != NULL) {
@@ -810,7 +808,7 @@ TcpBlockProc(
int mode) /* TCL_MODE_BLOCKING or
* TCL_MODE_NONBLOCKING. */
{
- SocketInfo *infoPtr = (SocketInfo *) instanceData;
+ SocketInfo *infoPtr = instanceData;
if (mode == TCL_MODE_NONBLOCKING) {
infoPtr->flags |= SOCKET_ASYNC;
@@ -844,7 +842,7 @@ TcpCloseProc(
ClientData instanceData, /* The socket to close. */
Tcl_Interp *interp) /* Unused. */
{
- SocketInfo *infoPtr = (SocketInfo *) instanceData;
+ SocketInfo *infoPtr = instanceData;
/* TIP #218 */
int errorCode = 0;
/* ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); */
@@ -902,7 +900,7 @@ TcpClose2Proc(
Tcl_Interp *interp, /* For error reporting. */
int flags) /* Flags that indicate which side to close. */
{
- SocketInfo *infoPtr = (SocketInfo *) instanceData;
+ SocketInfo *infoPtr = instanceData;
int errorCode = 0;
int sd;
@@ -919,7 +917,8 @@ TcpClose2Proc(
break;
default:
if (interp) {
- Tcl_AppendResult(interp, "Socket close2proc called bidirectionally", NULL);
+ Tcl_AppendResult(interp,
+ "Socket close2proc called bidirectionally", NULL);
}
return TCL_ERROR;
}
@@ -1018,8 +1017,7 @@ CreateSocket(
const char *errorMsg = NULL;
SOCKET sock = INVALID_SOCKET;
SocketInfo *infoPtr = NULL; /* The returned value. */
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- TclThreadDataKeyGet(&dataKey);
+ ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
/*
* Check that WinSock is initialized; do not call it if not, to prevent
@@ -1138,10 +1136,10 @@ CreateSocket(
}
}
} else {
- for (addrPtr = addrlist; addrPtr != NULL;
- addrPtr = addrPtr->ai_next) {
- for (myaddrPtr = myaddrlist; myaddrPtr != NULL;
- myaddrPtr = myaddrPtr->ai_next) {
+ for (addrPtr = addrlist; addrPtr != NULL;
+ addrPtr = addrPtr->ai_next) {
+ for (myaddrPtr = myaddrlist; myaddrPtr != NULL;
+ myaddrPtr = myaddrPtr->ai_next) {
/*
* No need to try combinations of local and remote addresses
* of different families.
@@ -1365,8 +1363,7 @@ WaitForSocketEvent(
{
int result = 1;
int oldMode;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- TclThreadDataKeyGet(&dataKey);
+ ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
/*
* Be sure to disable event servicing so we are truly modal.
@@ -1498,7 +1495,7 @@ Tcl_MakeTcpClientChannel(
return NULL;
}
- tsdPtr = (ThreadSpecificData *)TclThreadDataKeyGet(&dataKey);
+ tsdPtr = TclThreadDataKeyGet(&dataKey);
/*
* Set kernel space buffering and non-blocking.
@@ -1609,8 +1606,7 @@ TcpAccept(
SOCKADDR_IN addr;
int len;
char channelName[16 + TCL_INTEGER_SPACE];
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- TclThreadDataKeyGet(&dataKey);
+ ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
/*
* Accept the incoming connection request.
@@ -1723,11 +1719,10 @@ TcpInputProc(
int toRead, /* Maximum number of bytes to read. */
int *errorCodePtr) /* Where to store error codes. */
{
- SocketInfo *infoPtr = (SocketInfo *) instanceData;
+ SocketInfo *infoPtr = instanceData;
int bytesRead;
DWORD error;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- TclThreadDataKeyGet(&dataKey);
+ ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
*errorCodePtr = 0;
@@ -1861,11 +1856,10 @@ TcpOutputProc(
int toWrite, /* Maximum number of bytes to write. */
int *errorCodePtr) /* Where to store error codes. */
{
- SocketInfo *infoPtr = (SocketInfo *) instanceData;
+ SocketInfo *infoPtr = instanceData;
int bytesWritten;
DWORD error;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- TclThreadDataKeyGet(&dataKey);
+ ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
*errorCodePtr = 0;
@@ -1970,7 +1964,7 @@ TcpSetOptionProc(
const char *optionName, /* Name of the option to set. */
const char *value) /* New value for option. */
{
- SocketInfo *infoPtr;
+ SocketInfo *infoPtr = instanceData;
SOCKET sock;
/*
@@ -1986,7 +1980,6 @@ TcpSetOptionProc(
return TCL_ERROR;
}
- infoPtr = (SocketInfo *) instanceData;
sock = infoPtr->sockets->fd;
#ifdef TCL_FEATURE_KEEPALIVE_NAGLE
@@ -2070,7 +2063,7 @@ TcpGetOptionProc(
Tcl_DString *dsPtr) /* Where to store the computed value;
* initialized by caller. */
{
- SocketInfo *infoPtr;
+ SocketInfo *infoPtr = instanceData;
char host[NI_MAXHOST], port[NI_MAXSERV];
SOCKET sock;
size_t len = 0;
@@ -2090,7 +2083,6 @@ TcpGetOptionProc(
return TCL_ERROR;
}
- infoPtr = (SocketInfo *) instanceData;
sock = infoPtr->sockets->fd;
if (optionName != NULL) {
len = strlen(optionName);
@@ -2116,7 +2108,7 @@ TcpGetOptionProc(
}
if (interp != NULL && Tcl_GetVar(interp, SUPPRESS_RDNS_VAR, 0) != NULL) {
- reverseDNS = NI_NUMERICHOST;
+ reverseDNS = NI_NUMERICHOST;
}
if ((len == 0) || ((len > 1) && (optionName[1] == 'p') &&
@@ -2130,10 +2122,10 @@ TcpGetOptionProc(
}
getnameinfo(&(peername.sa), size, host, sizeof(host),
- NULL, 0, NI_NUMERICHOST);
+ NULL, 0, NI_NUMERICHOST);
Tcl_DStringAppendElement(dsPtr, host);
getnameinfo(&(peername.sa), size, host, sizeof(host),
- port, sizeof(port), reverseDNS | NI_NUMERICSERV);
+ port, sizeof(port), reverseDNS | NI_NUMERICSERV);
Tcl_DStringAppendElement(dsPtr, host);
Tcl_DStringAppendElement(dsPtr, port);
if (len == 0) {
@@ -2162,10 +2154,9 @@ TcpGetOptionProc(
if ((len == 0) || ((len > 1) && (optionName[1] == 's') &&
(strncmp(optionName, "-sockname", len) == 0))) {
-
TcpFdList *fds;
- address sockname;
- socklen_t size;
+ address sockname;
+ socklen_t size;
int found = 0;
if (len == 0) {
@@ -2180,7 +2171,7 @@ TcpGetOptionProc(
found = 1;
getnameinfo(&sockname.sa, size, host, sizeof(host),
- NULL, 0, NI_NUMERICHOST);
+ NULL, 0, NI_NUMERICHOST);
Tcl_DStringAppendElement(dsPtr, host);
/*
@@ -2194,17 +2185,17 @@ TcpGetOptionProc(
}
} else if (sockname.sa.sa_family == AF_INET6) {
if ((IN6_ARE_ADDR_EQUAL(&sockname.sa6.sin6_addr,
- &in6addr_any))
- || (IN6_IS_ADDR_V4MAPPED(&sockname.sa6.sin6_addr) &&
- sockname.sa6.sin6_addr.s6_addr[12] == 0 &&
- sockname.sa6.sin6_addr.s6_addr[13] == 0 &&
- sockname.sa6.sin6_addr.s6_addr[14] == 0 &&
- sockname.sa6.sin6_addr.s6_addr[15] == 0)) {
+ &in6addr_any)) ||
+ (IN6_IS_ADDR_V4MAPPED(&sockname.sa6.sin6_addr)
+ && sockname.sa6.sin6_addr.s6_addr[12] == 0
+ && sockname.sa6.sin6_addr.s6_addr[13] == 0
+ && sockname.sa6.sin6_addr.s6_addr[14] == 0
+ && sockname.sa6.sin6_addr.s6_addr[15] == 0)) {
flags |= NI_NUMERICHOST;
}
}
getnameinfo(&sockname.sa, size, host, sizeof(host),
- port, sizeof(port), flags);
+ port, sizeof(port), flags);
Tcl_DStringAppendElement(dsPtr, host);
Tcl_DStringAppendElement(dsPtr, port);
}
@@ -2219,7 +2210,7 @@ TcpGetOptionProc(
if (interp) {
TclWinConvertWSAError((DWORD) WSAGetLastError());
Tcl_AppendResult(interp, "can't get sockname: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_PosixError(interp), NULL);
}
return TCL_ERROR;
}
@@ -2253,8 +2244,7 @@ TcpGetOptionProc(
Tcl_DStringAppendElement(dsPtr, "-nagle");
}
optlen = sizeof(BOOL);
- getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&opt,
- &optlen);
+ getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, &optlen);
if (opt) {
Tcl_DStringAppendElement(dsPtr, "0");
} else {
@@ -2303,7 +2293,7 @@ TcpWatchProc(
* TCL_READABLE, TCL_WRITABLE and
* TCL_EXCEPTION. */
{
- SocketInfo *infoPtr = (SocketInfo *) instanceData;
+ SocketInfo *infoPtr = instanceData;
/*
* Update the watch events mask. Only if the socket is not a server
@@ -2354,7 +2344,7 @@ TcpGetHandleProc(
int direction, /* Not used. */
ClientData *handlePtr) /* Where to store the handle. */
{
- SocketInfo *statePtr = (SocketInfo *) instanceData;
+ SocketInfo *statePtr = instanceData;
*handlePtr = INT2PTR(statePtr->sockets->fd);
return TCL_OK;
@@ -2381,7 +2371,7 @@ SocketThread(
LPVOID arg)
{
MSG msg;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *) arg;
+ ThreadSpecificData *tsdPtr = arg;
/*
* Create a dummy window receiving socket events.
@@ -2779,7 +2769,7 @@ TcpThreadActionProc(
int action)
{
ThreadSpecificData *tsdPtr;
- SocketInfo *infoPtr = (SocketInfo *) instanceData;
+ SocketInfo *infoPtr = instanceData;
int notifyCmd;
if (action == TCL_CHANNEL_THREAD_INSERT) {