summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c11
1 files changed, 9 insertions, 2 deletions
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;
}