Index: tclIOCmd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIOCmd.c,v
retrieving revision 1.31
diff -u -r1.31 tclIOCmd.c
--- tclIOCmd.c	24 Aug 2005 17:56:23 -0000	1.31
+++ tclIOCmd.c	27 Sep 2005 04:45:39 -0000
@@ -241,12 +241,17 @@
     int lineLen;		/* Length of line just read. */
     int mode;			/* Mode in which channel is opened. */
     char *name;
+    CONST char *varname;
+    int varoff = 0;
+    int limit = 0;
     Tcl_Obj *linePtr;
+    CONST char errmsg[] = "channelId ?-limit limit? ?varName?";
 
-    if ((objc != 2) && (objc != 3)) {
-	Tcl_WrongNumArgs(interp, 1, objv, "channelId ?varName?");
+    if ((objc < 2) || (objc > 5)) {
+	Tcl_WrongNumArgs(interp, 1, objv, errmsg);
 	return TCL_ERROR;
     }
+
     name = Tcl_GetString(objv[1]);
     chan = Tcl_GetChannel(interp, name, &mode);
     if (chan == (Tcl_Channel) NULL) {
@@ -258,10 +263,44 @@
 	return TCL_ERROR;
     }
 
-    linePtr = Tcl_NewObj();
+    if (objc > 2) {
+	varname = Tcl_GetString(objv[2]);
+	varoff = 2;
+
+	if ((*varname == '-') && !strncmp(varname, "-limit", 6)) {
+	    if (objc == 5) {
+		varname = Tcl_GetString(objv[4]);
+		varoff = 4;
+	    } else {
+		varname = NULL;
+		varoff = 0;
+	    }
+
+	    /* get the limit */
+	    if (objc < 4) {
+		Tcl_WrongNumArgs(interp, 1, objv, errmsg);
+		return TCL_ERROR;
+	    }
+	    if (Tcl_GetInt(interp, Tcl_GetString(objv[3]), &limit) != TCL_OK) {
+		return TCL_ERROR;
+	    }
+	} else if (objc != 3) {
+	    Tcl_WrongNumArgs(interp, 1, objv, errmsg);
+	    return TCL_ERROR;
+	}
+    } else {
+	varname = NULL;
+	varoff = 0;
+    }
 
-    lineLen = Tcl_GetsObj(chan, linePtr);
+    linePtr = Tcl_NewObj();
+    if (limit) {
+	lineLen = Tcl_GetsObjLimit(chan, linePtr, limit);
+    } else {
+	lineLen = Tcl_GetsObj(chan, linePtr);
+    }
     if (lineLen < 0) {
+
 	if (!Tcl_Eof(chan) && !Tcl_InputBlocked(chan)) {
 	    Tcl_DecrRefCount(linePtr);
 
@@ -279,8 +318,8 @@
 	}
 	lineLen = -1;
     }
-    if (objc == 3) {
-	if (Tcl_ObjSetVar2(interp, objv[2], NULL, linePtr,
+    if (varname != NULL) {
+	if (Tcl_ObjSetVar2(interp, objv[varoff], NULL, linePtr,
 		TCL_LEAVE_ERR_MSG) == NULL) {
 	    Tcl_DecrRefCount(linePtr);
 	    return TCL_ERROR;
