diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | stream.c | 11 | ||||
-rw-r--r-- | txr.1 | 13 |
3 files changed, 28 insertions, 5 deletions
@@ -1,5 +1,14 @@ 2014-02-18 Kaz Kylheku <kaz@kylheku.com> + * stream.c (open_tail): Fix 2013-12-02 regression: + seek_to_end_p argument being ignored, with the + behavior being no initial seek to the end. + + * txr.1: Clarified the behavior of the seek-to-end-p + option. + +2014-02-18 Kaz Kylheku <kaz@kylheku.com> + * combi.c (rperm_gen_full): Update ptail with return value of list_collect. This is not necessary for correctness, but it spares list_collect from having to search for the tail on each call. @@ -2082,14 +2082,21 @@ val open_file(val path, val mode_str) val open_tail(val path, val mode_str, val seek_end_p) { + FILE *f = w_fopen(c_str(path), c_str(mode_str)); struct stdio_handle *h; val stream; unsigned long state = 0; - stream = make_tail_stream(0, path); + if (f && seek_end_p) + if (fseek(f, 0, SEEK_END) < 0) + uw_throwf(file_error_s, lit("error seeking to end of ~a: ~a/~s"), + path, num(errno), string_utf8(strerror(errno)), nao); + + stream = make_tail_stream(f, path); h = (struct stdio_handle *) stream->co.handle; h->mode = mode_str; - tail_strategy(stream, &state); + if (!f) + tail_strategy(stream, &state); return stream; } @@ -11628,9 +11628,16 @@ the same conventions as the mode argument of the C language fopen function. The mode string determines whether the stream is an input stream or output stream. Note that the "b" mode is not supported. Whether a stream is text or binary depends on which operations -are invoked on it. The <seek-to-end-p> argument is a boolean whcih -determines whether the initial read/write position is at the -start of the file, or just past the end. +are invoked on it. + +The <seek-to-end-p> argument is a boolean which determines whether the initial +read/write position is at the start of the file, or just past the end. This +argument only makes a difference if the file exists at the time open-tail is +called. If the file does not exist, and is later created, then the tail stream +will follow that file from the beginning. In other words, <seek-to-end-p> +controls whether the tail stream reads all the existing data in the file, if +any, or whether it reads only newly added data from approximately the time the +stream is created. A tail stream has special semantics with regard to reading at the end of file. A tail stream never reports an end-of-file condition; instead |