Re: Bug with g_file_load/replace_contents and utf-8



2009/6/30 Mike Massonnet <mmassonnet gmail com>:
Hello,

I have been porting a part of a program to GIO for file monitoring. By
this move I also switched g_file_get/set_contents to the ones
available in the GFile object, g_file_load/replace_contents.

At the first run I was surprised that it didn't work (of course errors
may always be introduced ;-)). Well looks like the code was ok. The
problem is that I read and save files with utf-8 characters and that
is kind of broken here. I reproduced the problem on two machines, one
with glib-2.20.1 and another with glib 2.20.3. I ran a smaller test
case, one in C as my program and another with Python. Turns out the
one in Python doesn't reproduce the problem and I really have no clue
what is going on. The test cases in C and Python are attached.

I hope I'm not the only one reproducing the problem :)

Did you read the documentation for g_file_replace_contents? You're
writing a string to the file of -1 bytes.
-    g_file_replace_contents (file, text, -1, NULL, FALSE, 0, NULL, NULL, NULL);
+   g_file_replace_contents (file, text, strlen (text), NULL, FALSE,
0, NULL, NULL, NULL);

works fine here.

-A. Walton


Mike

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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