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 658312 - GLib file_set_contents(string) doesn't encode string as utf
GLib file_set_contents(string) doesn't encode string as utf
Status: RESOLVED NOTABUG
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-09-06 02:45 UTC by arun
Modified: 2011-09-07 01:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description arun 2011-09-06 02:45:08 UTC
Environment: I am using gjs/gobject-introspection to call into GLib.file_set_contents.

Repro:
Call GLib.file_set_contents with gchar* contents="séance"

Expected behavior:
The saved file should contain following hex:
0000000: 73c3 a961 6e63 650a

Actual behavior:
Instead it contains following:
0000000: 73e9 616e 6365 0a

--
For "é", the character getting saved is _e9_ (which I suppose is ISO-8859 encoding); it should be saved as _c3a9_.

Some screenshots of this:
- http://ompldr.org/vYTU1dg/utf8_gjs.jpg
- http://ompldr.org/vYTU2cg/utf8_filediff.jpg
Comment 1 Matthias Clasen 2011-09-07 01:39:00 UTC
g_file_set_contents has no chance to do what you ask here, since it does not know what encoding the given string might be in. It is your responsibility to pass the contents in a suitable form.