Problems with GBufferedOutputStream



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

I came across a problem with GBufferedOutputStream and
g_output_stream_write recently. If I try to write more data than the
buffer size, not everything is written to the file.

The attached example should write:
0123456894568
This is just a simple textabcdefgh


But the contents actually are:
012345684568
Thi


Am I missing something or is this a bug?

- --
Greetings,
Sebastian Pölsterl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqFsdAACgkQ1ygZeJ3lLIeHBgCfeCq8iBKo++mN5uCox0EFEdeb
9eUAoJmIY3jxCyNm8ot4hXrlbNEqBR2F
=guiz
-----END PGP SIGNATURE-----
#include <glib.h>
#include <gio/gio.h>
#include <string.h>

#define TEXT1 "012345689"
#define TEXT2 "4568\n"
#define TEXT3 "abcdefgh\n"

int
main (int argc, char** argv)
{
  g_type_init ();

  GFile *file;
  GFileOutputStream *fostream;
  GOutputStream *bostream;
  GError *error = NULL;
  gchar *str;

  file = g_file_new_for_path ("test_file.txt");
  fostream = g_file_replace (file, NULL, TRUE, 0, NULL, &error);
  if (error != NULL) {
    g_critical ("CREATING: %s", error->message);
    g_error_free (error);
    return 1;
  }

  bostream = g_buffered_output_stream_new_sized (G_OUTPUT_STREAM (fostream), 8);

  g_output_stream_write (bostream, TEXT1, strlen(TEXT1),
      NULL, &error);
  if (error != NULL) {
    g_critical ("WRITING: %s", error->message);
    g_error_free (error);
    return 1;
  }

  g_output_stream_write (bostream, TEXT2, strlen(TEXT2),
      NULL, &error);
  if (error != NULL) {
    g_critical ("WRITING: %s", error->message);
    g_error_free (error);
    return 1;
  }

  str = g_strdup_printf ("This is just a simple text %s", TEXT3);
  g_output_stream_write (bostream, str, strlen(str),
      NULL, &error);
  if (error != NULL) {
    g_critical ("WRITING: %s", error->message);
    g_error_free (error);
    return 1;
  }
  g_free (str);

  g_output_stream_close (bostream, NULL, &error);
  if (error != NULL) {
    g_critical ("CLOSING: %s", error->message);
    g_error_free (error);
    return 1;
  }
  g_object_unref (file);
  g_object_unref (fostream);
  g_object_unref (bostream);

  return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]