GNOME Bugzilla – Bug 540461
g_memory_output_stream_get_data_size() doesn't behave as document
Last modified: 2009-02-26 15:41:46 UTC
The document says that function returns the number of bytes written to the stream, but actually that has the same behavior to g_seekable_tell(gmemoryoutputstream). which means current position, but not the number of bytes written.
"that has not been truncated away" seems to be the hint that this is indeed the intended behaviour. What would you expect to get when you ask for "the number of bytes written" ?
Sure. exactly writing something but affecting the data size by moving the position of the stream isn't intuitive for me. the position of the stream and the data size actually written should be managed separately. what the behavior I'm expecting is something like this: % cat t.c #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> int main(void) { int fd; struct stat st; fd = open("foo.txt", O_RDWR|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR); if (fd == -1) return 1; write(fd, "abc", 3); fsync(fd); lseek(fd, 0, SEEK_SET); if (fstat(fd, &st) == -1) { close(fd); return 1; } printf("%ld\n", st.st_size); close(fd); return 0; } % gcc t.c % /a.out 3
Yeah, we need to track three things: allocated length (len currently) write possition (pos currently) max written position (not tracked currently)
2009-02-26 Alexander Larsson <alexl@redhat.com> Bug 540461 – g_memory_output_stream_get_data_size() doesn't behave as document * gmemoryoutputstream.c: Track actual valid size, even if we later seek back. * tests/memory-output-stream.c: Add testcase