summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-03-19 17:05:33 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-03-19 17:05:33 -0700
commit492d3047105372acc93e4050de35894a19e63715 (patch)
tree1db096f9be49580788740782a7aa1f31ccc9d8d2 /stream.c
parent8d338fb27ee545c4f2fc90963f8d0c70af478b66 (diff)
downloadtxr-492d3047105372acc93e4050de35894a19e63715.tar.gz
txr-492d3047105372acc93e4050de35894a19e63715.tar.bz2
txr-492d3047105372acc93e4050de35894a19e63715.zip
Improve treatment of open mode in tail streams.
* stream.c (tail_strategy): Apply the mode whenever a new stream is opened. (open_tail): Store the original mode string in h->mode rather than the normalized one, so in tail_strategy we can apply all the same attributes to a newly opened stream that we applied to the original stream.
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 713671cb..76d0c3cb 100644
--- a/stream.c
+++ b/stream.c
@@ -896,6 +896,8 @@ static void tail_strategy(val stream, unsigned long *state)
{
struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle);
int sec = 0, mod = 0;
+ val mode = nil;
+ struct stdio_mode m, m_r = stdio_mode_init_r;
tail_calc(state, &sec, &mod);
@@ -926,9 +928,12 @@ static void tail_strategy(val stream, unsigned long *state)
for (;;) {
FILE *newf;
+ if (!mode)
+ mode = normalize_mode(&m, h->mode, m_r);
+
/* Try to open the file.
*/
- if (!(newf = w_fopen(c_str(h->descr), c_str(h->mode)))) {
+ if (!(newf = w_fopen(c_str(h->descr), c_str(mode)))) {
/* If already have the file open previously, and the name
* does not open any more, then the file has rotated.
* Have the caller try to read the last bit of data
@@ -952,6 +957,7 @@ static void tail_strategy(val stream, unsigned long *state)
*/
if (!h->f) {
h->f = newf;
+ (void) set_mode_props(m, stream);
break;
}
@@ -987,6 +993,7 @@ static void tail_strategy(val stream, unsigned long *state)
fseek(newf, save_pos, SEEK_SET);
fclose(h->f);
h->f = newf;
+ (void) set_mode_props(m, stream);
return;
}
@@ -3394,7 +3401,7 @@ val open_tail(val path, val mode_str, val seek_end_p)
stream = make_tail_stream(f, path);
h = coerce(struct stdio_handle *, stream->co.handle);
- h->mode = mode;
+ h->mode = mode_str;
if (!f)
tail_strategy(stream, &state);
return set_mode_props(m, stream);