I’m updating an old gtk2 application to gtk3. First time using gtk3. The old app used gnome_vfs, and I’ve been using gio as the replacement. Everything finally compiles and I’m starting to debug. So far so good. Until day before yesterday when I reached a part in the code that tries to seek to offset 700 in a file. Instead of positioning to 700, it positions to +1 past the furthest point read in the file (179 as a recall in that case).
After much hair pulling it came down to not seeking to the correct location. So I changed the internal code that opens files to include a simple test every time a file is opened and it doesn’t appear to matter what the file is, it won’t seek. Reads work fine.
Here is the code (minus return value checks, no errors returned in my tests, but reduces code complexity for easier viewing here):
fh->gfile = g_file_new_for_path(filename);
fh->f.inputStream = g_file_read(fh->gfile, NULL, NULL);
printf("TEST: Open fpos:%ld\n", g_seekable_tell(G_SEEKABLE(fh->f.inputStream)));
g_seekable_seek(G_SEEKABLE(fh->f.inputStream), G_SEEK_SET, 700, NULL, NULL);
printf("TEST: After SET 700 fpos:%ld\n", g_seekable_tell(G_SEEKABLE(fh->f.inputStream)));
g_seekable_seek(G_SEEKABLE(fh->f.inputStream), G_SEEK_END, 0, NULL, NULL);
printf("TEST: After END 0 fpos:%ld\n", g_seekable_tell(G_SEEKABLE(fh->f.inputStream)));
g_seekable_seek(G_SEEKABLE(fh->f.inputStream), G_SEEK_SET, 700, NULL, NULL);
printf("TEST: After second SET 700 fpos:%ld\n", g_seekable_tell(G_SEEKABLE(fh->f.inputStream)));
g_seekable_seek(G_SEEKABLE(fh->f.inputStream), G_SEEK_END, 0, NULL, NULL);
printf("TEST: After second END 0 fpos:%ld\n", g_seekable_tell(G_SEEKABLE(fh->f.inputStream)));
g_seekable_seek(G_SEEKABLE(fh->f.inputStream), G_SEEK_SET, 700, NULL, NULL);
printf("TEST: After third SET 700 fpos:%ld\n", g_seekable_tell(G_SEEKABLE(fh->f.inputStream)));
g_seekable_seek(G_SEEKABLE(fh->f.inputStream), G_SEEK_SET, 0, NULL, NULL);
printf("TEST: After SET 0 fpos:%ld\n", g_seekable_tell(G_SEEKABLE(fh->f.inputStream)));
Without fail, what I get for every file opened is:
TEST: Open fpos:0
TEST: After SET 700 fpos:1
TEST: After END 0 fpos:3
TEST: After second SET 700 fpos:4
TEST: After second END 0 fpos:6
TEST: After third SET 700 fpos:7
TEST: After SET 0 fpos:8
It is as if it some some kind of linear stream. Is g_file_read not the correct call to open a file on disk? I feel like this is some kind of too close to see the problem.
Thanks for any and all help!