Index: generic/tclIO.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIO.c,v
retrieving revision 1.61.2.17
diff -u -r1.61.2.17 tclIO.c
--- generic/tclIO.c	18 Nov 2005 19:38:02 -0000	1.61.2.17
+++ generic/tclIO.c	15 Feb 2006 16:01:02 -0000
@@ -1310,8 +1310,10 @@
     }
 
     if (statePtr == NULL) {
-	Tcl_AppendResult(interp, "couldn't find state for channel \"",
-		Tcl_GetChannelName(prevChan), "\"", (char *) NULL);
+	if (interp) {
+	    Tcl_AppendResult(interp, "couldn't find state for channel \"",
+		    Tcl_GetChannelName(prevChan), "\"", (char *) NULL);
+	}
         return (Tcl_Channel) NULL;
     }
 
@@ -1329,9 +1331,11 @@
      */
 
     if ((mask & (statePtr->flags & (TCL_READABLE | TCL_WRITABLE))) == 0) {
-	Tcl_AppendResult(interp,
-		"reading and writing both disallowed for channel \"",
-		Tcl_GetChannelName(prevChan), "\"", (char *) NULL);
+	if (interp) {
+	    Tcl_AppendResult(interp,
+		    "reading and writing both disallowed for channel \"",
+		    Tcl_GetChannelName(prevChan), "\"", (char *) NULL);
+	}
         return (Tcl_Channel) NULL;
     }
 
@@ -1350,8 +1354,10 @@
 
 	if (Tcl_Flush((Tcl_Channel) prevChanPtr) != TCL_OK) {
 	    statePtr->csPtr = csPtr;
-	    Tcl_AppendResult(interp, "could not flush channel \"",
-		    Tcl_GetChannelName(prevChan), "\"", (char *) NULL);
+	    if (interp) {
+		Tcl_AppendResult(interp, "could not flush channel \"",
+			Tcl_GetChannelName(prevChan), "\"", (char *) NULL);
+	    }
 	    return (Tcl_Channel) NULL;
 	}
 
@@ -1477,9 +1483,11 @@
 
 	    if (Tcl_Flush((Tcl_Channel) chanPtr) != TCL_OK) {
 	        statePtr->csPtr = csPtr;
-		Tcl_AppendResult(interp, "could not flush channel \"",
-			Tcl_GetChannelName((Tcl_Channel) chanPtr), "\"",
-			(char *) NULL);
+		if (interp) {
+		    Tcl_AppendResult(interp, "could not flush channel \"",
+			    Tcl_GetChannelName((Tcl_Channel) chanPtr), "\"",
+			    (char *) NULL);
+		}
 		return TCL_ERROR;
 	    }
 
@@ -2562,9 +2570,11 @@
     }
  
     if (statePtr->flags & CHANNEL_INCLOSE) {
-        Tcl_AppendResult(interp,
-	 "Illegal recursive call to close through close-handler of channel",
-	 (char *) NULL);
+	if (interp) {
+            Tcl_AppendResult(interp,
+	    "Illegal recursive call to close through close-handler of channel",
+	    (char *) NULL);
+	}
         return TCL_ERROR;
     }
     statePtr->flags |= CHANNEL_INCLOSE;
@@ -7574,13 +7584,17 @@
     outStatePtr	= outPtr->state;
 
     if (inStatePtr->csPtr) {
-	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "channel \"",
-		Tcl_GetChannelName(inChan), "\" is busy", NULL);
+	if (interp) {
+	    Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "channel \"",
+		    Tcl_GetChannelName(inChan), "\" is busy", NULL);
+	}
 	return TCL_ERROR;
     }
     if (outStatePtr->csPtr) {
-	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "channel \"",
-		Tcl_GetChannelName(outChan), "\" is busy", NULL);
+	if (interp) {
+	    Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "channel \"",
+		    Tcl_GetChannelName(outChan), "\" is busy", NULL);
+	}
 	return TCL_ERROR;
     }
 
@@ -7882,7 +7896,7 @@
      */
 
     total = csPtr->total;
-    if (cmdPtr) {
+    if (cmdPtr && interp) {
 	/*
 	 * Get a private copy of the command so we can mutate it
 	 * by adding arguments.  Note that StopCopy frees our saved
@@ -7906,12 +7920,14 @@
 	Tcl_Release((ClientData) interp);
     } else {
 	StopCopy(csPtr);
-	if (errObj) {
-	    Tcl_SetObjResult(interp, errObj);
-	    result = TCL_ERROR;
-	} else {
-	    Tcl_ResetResult(interp);
-	    Tcl_SetIntObj(Tcl_GetObjResult(interp), total);
+	if (interp) {
+	    if (errObj) {
+		Tcl_SetObjResult(interp, errObj);
+		result = TCL_ERROR;
+	    } else {
+		Tcl_ResetResult(interp);
+		Tcl_SetIntObj(Tcl_GetObjResult(interp), total);
+	    }
 	}
     }
     return result;
Index: generic/tclIOUtil.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIOUtil.c,v
retrieving revision 1.77.2.25
diff -u -r1.77.2.25 tclIOUtil.c
--- generic/tclIOUtil.c	12 Jan 2006 18:03:48 -0000	1.77.2.25
+++ generic/tclIOUtil.c	15 Feb 2006 16:01:03 -0000
@@ -1864,7 +1864,9 @@
 
     msg = Tcl_ErrnoMsg(errno);
     id = Tcl_ErrnoId();
-    Tcl_SetErrorCode(interp, "POSIX", id, msg, (char *) NULL);
+    if (interp) {
+	Tcl_SetErrorCode(interp, "POSIX", id, msg, (char *) NULL);
+    }
     return msg;
 }
 
