Tcl Source Code

Artifact [d59df24c72]
Login

Artifact d59df24c72e996699b75755869bdad639d781e2b:

Attachment "85.append.udiff" to ticket [680143ffff] added by andreas_kupries 2006-03-17 01:25:02.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tcl/tcl/ChangeLog,v
retrieving revision 1.2977
diff -w -u -r1.2977 ChangeLog
--- ChangeLog	16 Mar 2006 00:38:50 -0000	1.2977
+++ ChangeLog	16 Mar 2006 18:20:50 -0000
@@ -1,3 +1,13 @@
+2006-03-16  Andreas Kupries <[email protected]>
+
+	* generic/tclIOUtil.c (TclGetOpenMode): Added the flag O_APPEND to
+	  the list of POSIX modes used when opening a file for
+	  'a'ppend. This enables the proper automatic seek-to-end-on-write
+	  by the OS. See [Bug 680143] for longer discussion.
+
+	* tests/ioCmd.test (iocmd-13.7.*): Extended the testsuite to check
+	  the new handling of 'a'.
+
 2006-03-15  Andreas Kupries <[email protected]>
 
 	* tests/socket.test: Extended the timeout in socket-11.11 from 10
Index: generic/tclIOUtil.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIOUtil.c,v
retrieving revision 1.128
diff -w -u -r1.128 tclIOUtil.c
--- generic/tclIOUtil.c	15 Feb 2006 15:43:55 -0000	1.128
+++ generic/tclIOUtil.c	16 Mar 2006 18:20:50 -0000
@@ -1558,7 +1558,11 @@
 	    mode = O_WRONLY|O_CREAT|O_TRUNC;
 	    break;
 	case 'a':
-	    mode = O_WRONLY|O_CREAT;
+	    /* [Bug 680143].
+	     * Added O_APPEND for proper automatic
+	     * seek-to-end-on-write by the OS.
+	     */
+	    mode = O_WRONLY|O_CREAT|O_APPEND;
 	    *seekFlagPtr = 1;
 	    break;
 	default:
Index: tests/ioCmd.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/ioCmd.test,v
retrieving revision 1.27
diff -w -u -r1.27 ioCmd.test
--- tests/ioCmd.test	17 Feb 2006 16:16:47 -0000	1.27
+++ tests/ioCmd.test	16 Mar 2006 18:20:51 -0000
@@ -503,6 +503,38 @@
     list [catch {open $path(test1) r++} msg] $msg
 } {1 {illegal access mode "r++"}}
 
+test iocmd-13.10.1 {open for append, a mode} -setup {
+    set log   [makeFile {} out]
+    set chans {}
+} -body {
+    foreach i { 0 1 2 3 4 5 6 7 8 9 } {
+	puts [set ch [open $log a]] $i
+	lappend chans $ch
+    }
+    foreach ch $chans {catch {close $ch}}
+    lsort [split [string trim [viewFile out]] \n]
+} -cleanup {
+    removeFile out
+    # Ensure that channels are gone, even if body failed to do so
+    foreach ch $chans {catch {close $ch}}
+} -result {0 1 2 3 4 5 6 7 8 9}
+
+test iocmd-13.10.2 {open for append, O_APPEND} -setup {
+    set log   [makeFile {} out]
+    set chans {}
+} -body {
+    foreach i { 0 1 2 3 4 5 6 7 8 9 } {
+	puts [set ch [open $log {WRONLY CREAT APPEND}]] $i
+	lappend chans $ch
+    }
+    foreach ch $chans {catch {close $ch}}
+    lsort [split [string trim [viewFile out]] \n]
+} -cleanup {
+    removeFile out
+    # Ensure that channels are gone, even if body failed to do so
+    foreach ch $chans {catch {close $ch}}
+} -result {0 1 2 3 4 5 6 7 8 9}
+
 test iocmd-14.1 {file id parsing errors} {
     list [catch {eof gorp} msg] $msg $errorCode
 } {1 {can not find channel named "gorp"} NONE}