After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 540461 - g_memory_output_stream_get_data_size() doesn't behave as document
g_memory_output_stream_get_data_size() doesn't behave as document
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.17.x
Other Linux
: Normal normal
: ---
Assigned To: Alexander Larsson
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-06-27 10:59 UTC by Akira TAGOH
Modified: 2009-02-26 15:41 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Akira TAGOH 2008-06-27 10:59:52 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.
Comment 1 Matthias Clasen 2008-06-30 02:57:34 UTC
"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" ?
Comment 2 Akira TAGOH 2008-06-30 17:25:25 UTC
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
Comment 3 Alexander Larsson 2009-02-25 15:55:20 UTC
Yeah, we need to track three things:

allocated length (len currently)
write possition (pos currently)
max written position (not tracked currently)

Comment 4 Alexander Larsson 2009-02-26 15:41:46 UTC
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