From: P. F. Chimento Date: Sat, 18 Jun 2011 20:45:11 +0000 (+0200) Subject: Keep an EOF mark for memory streams X-Git-Tag: v0.9~73^2~1^2 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=bea353f718967322136bfe95b04d1de02084671a;p=projects%2Fchimara%2Fchimara.git Keep an EOF mark for memory streams Seeking to seekmode_End in a memory stream should move relative to the last written position in the buffer, not the end of the memory buffer. This brings the behavior of memory streams into line with what would happen in a file stream. Fixes #30. --- diff --git a/libchimara/stream.c b/libchimara/stream.c index 0113b98..96ab73f 100644 --- a/libchimara/stream.c +++ b/libchimara/stream.c @@ -284,6 +284,7 @@ glk_stream_open_memory(char *buf, glui32 buflen, glui32 fmode, glui32 rock) str->file_mode = fmode; str->type = STREAM_TYPE_MEMORY; str->mark = 0; + str->endmark = 0; str->unicode = FALSE; if(buf && buflen) @@ -322,6 +323,7 @@ glk_stream_open_memory_uni(glui32 *buf, glui32 buflen, glui32 fmode, glui32 rock str->file_mode = fmode; str->type = STREAM_TYPE_MEMORY; str->mark = 0; + str->endmark = 0; str->unicode = TRUE; if(buf && buflen) diff --git a/libchimara/stream.h b/libchimara/stream.h index 325b668..7ff7618 100644 --- a/libchimara/stream.h +++ b/libchimara/stream.h @@ -42,6 +42,7 @@ struct glk_stream_struct gchar *buffer; glui32 *ubuffer; glui32 mark; + glui32 endmark; glui32 buflen; gidispatch_rock_t buffer_rock; /* Specific to file streams */ diff --git a/libchimara/strio.c b/libchimara/strio.c index 039e189..b0d0fd1 100644 --- a/libchimara/strio.c +++ b/libchimara/strio.c @@ -310,6 +310,10 @@ write_buffer_to_stream(strid_t str, gchar *buf, glui32 len) str->mark += copycount; } + /* Move the EOF marker if we wrote past it */ + if(str->mark > str->endmark) + str->endmark = str->mark; + str->write_count += len; break; @@ -402,6 +406,10 @@ write_buffer_to_stream_uni(strid_t str, glui32 *buf, glui32 len) str->mark += copycount; } + /* Move the EOF marker if we wrote past it */ + if(str->mark > str->endmark) + str->endmark = str->mark; + str->write_count += len; break; @@ -1343,7 +1351,7 @@ glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode) { case seekmode_Start: str->mark = pos; break; case seekmode_Current: str->mark += pos; break; - case seekmode_End: str->mark = str->buflen + pos; break; + case seekmode_End: str->mark = str->endmark + pos; break; default: g_return_if_reached(); return;