summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-18 07:33:00 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-18 16:51:13 -0800
commit96f301c72e7ca9ec7be0d1453f89fa8e6d49ee85 (patch)
tree0400ac1f5fc914a1991e4e2008980f9b937372bd
parent4541ae4bec106d3d680edf3c25ca8f80287a83c9 (diff)
downloadtxr-96f301c72e7ca9ec7be0d1453f89fa8e6d49ee85.tar.gz
txr-96f301c72e7ca9ec7be0d1453f89fa8e6d49ee85.tar.bz2
txr-96f301c72e7ca9ec7be0d1453f89fa8e6d49ee85.zip
* 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.
-rw-r--r--ChangeLog9
-rw-r--r--stream.c11
-rw-r--r--txr.113
3 files changed, 28 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 2b1d4886..abfb9ae8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/stream.c b/stream.c
index 9dd0b742..5b1b966c 100644
--- a/stream.c
+++ b/stream.c
@@ -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;
}
diff --git a/txr.1 b/txr.1
index a9a6d9ab..518fdc20 100644
--- a/txr.1
+++ b/txr.1
@@ -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