GNOME Bugzilla – Bug 159664
g_get_home_dir (and g_get_tmp_dir) no longer works with "non-7-bit" home dir on win32
Last modified: 2004-12-22 21:47:04 UTC
Using glib from CVS HEAD, g_get_home_dir no longer works when my home directory contains non-7-bit characters such as "Ö" and its location is fetched from environment variables. The filename encoding patch from bug 101792 seems to have broken this. I think the problem is that g_get_any_init in glib/gutils.c doesn't convert the values from the environment variables (for example HOME or USERPROFILE) to UTF-8 before storing in g_home_dir. The home dir is "C:\Documents and Settings\Robert Ögren" and I'm running on Windows XP. I have tested this with a simple program that calls g_get_home_dir. If the program is compiled against glib-2-4, g_get_home_dir returns the correct dir when the program is run with the glib-2-4 binaries in the path, and returns NULL when the program is run with the HEAD binaries in the path. When the program is compiled and run against HEAD glib binaries, g_get_home_dir returns a directory but g_filename_to_utf8 then fails on it. I have tested both using cmd.exe (where USERPROFILE is the only thing set), and Cygwin bash (where HOME is set also). The same problem seems to affect g_get_tmp_dir as well (actually for me TEMP and TMP are usually set to the lovely short name version, C:\DOCUME~1\ROBERT~1\LOKALA~1\Temp ...).
Created attachment 34200 [details] Simple test program Here's the test program I used.
The bug #101792 changes to gutils.c were buggy; will fix. Will also change g_get_user_name() and g_get_real_name to return UTF-8, and add binary compatibility versions for them, too, that will continue to return system codepage strings.
Created attachment 34228 [details] [review] Suggested patch Please test.
Created attachment 34229 [details] [review] Dosc patch
Comment on attachment 34228 [details] [review] Suggested patch It looks good except for one serious bug - if HOME is not set, then home_utf8 is used even though it is uninitialized. After I changed that, it works fine without HOME as well. (If one runs in a Cygwin bash shell, the USERPROFILE environment variable is in some other encoding and must be unset if HOME is not set. I guess Cygwin converts it. If I run from cmd.exe, USERPROFILE is correct. So it should work fine in all normal cases :) I also had to remove g_file_tree_walk from glib.symbols to make it compile, I can't find that function anywhere in the sources?
Oops, thanks. The g_file_tree_walk was a leftover from testing a suggested API addition. Fix committed.