1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-1999 Tor Lillqvist
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GLib Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GLib at ftp://ftp.gtk.org/pub/gtk/.
29 * MT safe for the unix part, FIXME: make the win32 part MT safe as well.
34 #include "glibconfig.h"
42 #define STRICT /* Strict typing, please */
58 #include <sys/cygwin.h>
64 g_win32_ftruncate (gint fd,
67 return _chsize (fd, size);
75 * The setlocale() function in the Microsoft C library uses locale
76 * names of the form "English_United States.1252" etc. We want the
77 * UNIXish standard form "en_US", "zh_TW" etc. This function gets the
78 * current thread locale from Windows - without any encoding info -
79 * and returns it as a string of the above form for use in forming
80 * file names etc. The returned string should be deallocated with
83 * Returns: newly-allocated locale name.
86 /* Borrowed from GNU gettext 0.13.1: */
87 /* Mingw headers don't have latest language and sublanguage codes. */
88 #ifndef LANG_AFRIKAANS
89 #define LANG_AFRIKAANS 0x36
92 #define LANG_ALBANIAN 0x1c
95 #define LANG_AMHARIC 0x5e
98 #define LANG_ARABIC 0x01
100 #ifndef LANG_ARMENIAN
101 #define LANG_ARMENIAN 0x2b
103 #ifndef LANG_ASSAMESE
104 #define LANG_ASSAMESE 0x4d
107 #define LANG_AZERI 0x2c
110 #define LANG_BASQUE 0x2d
112 #ifndef LANG_BELARUSIAN
113 #define LANG_BELARUSIAN 0x23
116 #define LANG_BENGALI 0x45
119 #define LANG_BURMESE 0x55
121 #ifndef LANG_CAMBODIAN
122 #define LANG_CAMBODIAN 0x53
125 #define LANG_CATALAN 0x03
127 #ifndef LANG_CHEROKEE
128 #define LANG_CHEROKEE 0x5c
131 #define LANG_DIVEHI 0x65
134 #define LANG_EDO 0x66
136 #ifndef LANG_ESTONIAN
137 #define LANG_ESTONIAN 0x25
139 #ifndef LANG_FAEROESE
140 #define LANG_FAEROESE 0x38
143 #define LANG_FARSI 0x29
146 #define LANG_FRISIAN 0x62
148 #ifndef LANG_FULFULDE
149 #define LANG_FULFULDE 0x67
152 #define LANG_GAELIC 0x3c
154 #ifndef LANG_GALICIAN
155 #define LANG_GALICIAN 0x56
157 #ifndef LANG_GEORGIAN
158 #define LANG_GEORGIAN 0x37
161 #define LANG_GUARANI 0x74
163 #ifndef LANG_GUJARATI
164 #define LANG_GUJARATI 0x47
167 #define LANG_HAUSA 0x68
169 #ifndef LANG_HAWAIIAN
170 #define LANG_HAWAIIAN 0x75
173 #define LANG_HEBREW 0x0d
176 #define LANG_HINDI 0x39
179 #define LANG_IBIBIO 0x69
182 #define LANG_IGBO 0x70
184 #ifndef LANG_INDONESIAN
185 #define LANG_INDONESIAN 0x21
187 #ifndef LANG_INUKTITUT
188 #define LANG_INUKTITUT 0x5d
191 #define LANG_KANNADA 0x4b
194 #define LANG_KANURI 0x71
196 #ifndef LANG_KASHMIRI
197 #define LANG_KASHMIRI 0x60
200 #define LANG_KAZAK 0x3f
203 #define LANG_KONKANI 0x57
206 #define LANG_KYRGYZ 0x40
209 #define LANG_LAO 0x54
212 #define LANG_LATIN 0x76
215 #define LANG_LATVIAN 0x26
217 #ifndef LANG_LITHUANIAN
218 #define LANG_LITHUANIAN 0x27
220 #ifndef LANG_MACEDONIAN
221 #define LANG_MACEDONIAN 0x2f
224 #define LANG_MALAY 0x3e
226 #ifndef LANG_MALAYALAM
227 #define LANG_MALAYALAM 0x4c
230 #define LANG_MALTESE 0x3a
232 #ifndef LANG_MANIPURI
233 #define LANG_MANIPURI 0x58
236 #define LANG_MARATHI 0x4e
238 #ifndef LANG_MONGOLIAN
239 #define LANG_MONGOLIAN 0x50
242 #define LANG_NEPALI 0x61
245 #define LANG_ORIYA 0x48
248 #define LANG_OROMO 0x72
250 #ifndef LANG_PAPIAMENTU
251 #define LANG_PAPIAMENTU 0x79
254 #define LANG_PASHTO 0x63
257 #define LANG_PUNJABI 0x46
259 #ifndef LANG_RHAETO_ROMANCE
260 #define LANG_RHAETO_ROMANCE 0x17
263 #define LANG_SAAMI 0x3b
265 #ifndef LANG_SANSKRIT
266 #define LANG_SANSKRIT 0x4f
269 #define LANG_SERBIAN 0x1a
272 #define LANG_SINDHI 0x59
274 #ifndef LANG_SINHALESE
275 #define LANG_SINHALESE 0x5b
278 #define LANG_SLOVAK 0x1b
281 #define LANG_SOMALI 0x77
284 #define LANG_SORBIAN 0x2e
287 #define LANG_SUTU 0x30
290 #define LANG_SWAHILI 0x41
293 #define LANG_SYRIAC 0x5a
296 #define LANG_TAGALOG 0x64
299 #define LANG_TAJIK 0x28
301 #ifndef LANG_TAMAZIGHT
302 #define LANG_TAMAZIGHT 0x5f
305 #define LANG_TAMIL 0x49
308 #define LANG_TATAR 0x44
311 #define LANG_TELUGU 0x4a
314 #define LANG_THAI 0x1e
317 #define LANG_TIBETAN 0x51
319 #ifndef LANG_TIGRINYA
320 #define LANG_TIGRINYA 0x73
323 #define LANG_TSONGA 0x31
326 #define LANG_TSWANA 0x32
329 #define LANG_TURKMEN 0x42
331 #ifndef LANG_UKRAINIAN
332 #define LANG_UKRAINIAN 0x22
335 #define LANG_URDU 0x20
338 #define LANG_UZBEK 0x43
341 #define LANG_VENDA 0x33
343 #ifndef LANG_VIETNAMESE
344 #define LANG_VIETNAMESE 0x2a
347 #define LANG_WELSH 0x52
350 #define LANG_XHOSA 0x34
356 #define LANG_YIDDISH 0x3d
359 #define LANG_YORUBA 0x6a
362 #define LANG_ZULU 0x35
364 #ifndef SUBLANG_ARABIC_SAUDI_ARABIA
365 #define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
367 #ifndef SUBLANG_ARABIC_IRAQ
368 #define SUBLANG_ARABIC_IRAQ 0x02
370 #ifndef SUBLANG_ARABIC_EGYPT
371 #define SUBLANG_ARABIC_EGYPT 0x03
373 #ifndef SUBLANG_ARABIC_LIBYA
374 #define SUBLANG_ARABIC_LIBYA 0x04
376 #ifndef SUBLANG_ARABIC_ALGERIA
377 #define SUBLANG_ARABIC_ALGERIA 0x05
379 #ifndef SUBLANG_ARABIC_MOROCCO
380 #define SUBLANG_ARABIC_MOROCCO 0x06
382 #ifndef SUBLANG_ARABIC_TUNISIA
383 #define SUBLANG_ARABIC_TUNISIA 0x07
385 #ifndef SUBLANG_ARABIC_OMAN
386 #define SUBLANG_ARABIC_OMAN 0x08
388 #ifndef SUBLANG_ARABIC_YEMEN
389 #define SUBLANG_ARABIC_YEMEN 0x09
391 #ifndef SUBLANG_ARABIC_SYRIA
392 #define SUBLANG_ARABIC_SYRIA 0x0a
394 #ifndef SUBLANG_ARABIC_JORDAN
395 #define SUBLANG_ARABIC_JORDAN 0x0b
397 #ifndef SUBLANG_ARABIC_LEBANON
398 #define SUBLANG_ARABIC_LEBANON 0x0c
400 #ifndef SUBLANG_ARABIC_KUWAIT
401 #define SUBLANG_ARABIC_KUWAIT 0x0d
403 #ifndef SUBLANG_ARABIC_UAE
404 #define SUBLANG_ARABIC_UAE 0x0e
406 #ifndef SUBLANG_ARABIC_BAHRAIN
407 #define SUBLANG_ARABIC_BAHRAIN 0x0f
409 #ifndef SUBLANG_ARABIC_QATAR
410 #define SUBLANG_ARABIC_QATAR 0x10
412 #ifndef SUBLANG_AZERI_LATIN
413 #define SUBLANG_AZERI_LATIN 0x01
415 #ifndef SUBLANG_AZERI_CYRILLIC
416 #define SUBLANG_AZERI_CYRILLIC 0x02
418 #ifndef SUBLANG_BENGALI_INDIA
419 #define SUBLANG_BENGALI_INDIA 0x00
421 #ifndef SUBLANG_BENGALI_BANGLADESH
422 #define SUBLANG_BENGALI_BANGLADESH 0x01
424 #ifndef SUBLANG_CHINESE_MACAU
425 #define SUBLANG_CHINESE_MACAU 0x05
427 #ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
428 #define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
430 #ifndef SUBLANG_ENGLISH_JAMAICA
431 #define SUBLANG_ENGLISH_JAMAICA 0x08
433 #ifndef SUBLANG_ENGLISH_CARIBBEAN
434 #define SUBLANG_ENGLISH_CARIBBEAN 0x09
436 #ifndef SUBLANG_ENGLISH_BELIZE
437 #define SUBLANG_ENGLISH_BELIZE 0x0a
439 #ifndef SUBLANG_ENGLISH_TRINIDAD
440 #define SUBLANG_ENGLISH_TRINIDAD 0x0b
442 #ifndef SUBLANG_ENGLISH_ZIMBABWE
443 #define SUBLANG_ENGLISH_ZIMBABWE 0x0c
445 #ifndef SUBLANG_ENGLISH_PHILIPPINES
446 #define SUBLANG_ENGLISH_PHILIPPINES 0x0d
448 #ifndef SUBLANG_ENGLISH_INDONESIA
449 #define SUBLANG_ENGLISH_INDONESIA 0x0e
451 #ifndef SUBLANG_ENGLISH_HONGKONG
452 #define SUBLANG_ENGLISH_HONGKONG 0x0f
454 #ifndef SUBLANG_ENGLISH_INDIA
455 #define SUBLANG_ENGLISH_INDIA 0x10
457 #ifndef SUBLANG_ENGLISH_MALAYSIA
458 #define SUBLANG_ENGLISH_MALAYSIA 0x11
460 #ifndef SUBLANG_ENGLISH_SINGAPORE
461 #define SUBLANG_ENGLISH_SINGAPORE 0x12
463 #ifndef SUBLANG_FRENCH_LUXEMBOURG
464 #define SUBLANG_FRENCH_LUXEMBOURG 0x05
466 #ifndef SUBLANG_FRENCH_MONACO
467 #define SUBLANG_FRENCH_MONACO 0x06
469 #ifndef SUBLANG_FRENCH_WESTINDIES
470 #define SUBLANG_FRENCH_WESTINDIES 0x07
472 #ifndef SUBLANG_FRENCH_REUNION
473 #define SUBLANG_FRENCH_REUNION 0x08
475 #ifndef SUBLANG_FRENCH_CONGO
476 #define SUBLANG_FRENCH_CONGO 0x09
478 #ifndef SUBLANG_FRENCH_SENEGAL
479 #define SUBLANG_FRENCH_SENEGAL 0x0a
481 #ifndef SUBLANG_FRENCH_CAMEROON
482 #define SUBLANG_FRENCH_CAMEROON 0x0b
484 #ifndef SUBLANG_FRENCH_COTEDIVOIRE
485 #define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
487 #ifndef SUBLANG_FRENCH_MALI
488 #define SUBLANG_FRENCH_MALI 0x0d
490 #ifndef SUBLANG_FRENCH_MOROCCO
491 #define SUBLANG_FRENCH_MOROCCO 0x0e
493 #ifndef SUBLANG_FRENCH_HAITI
494 #define SUBLANG_FRENCH_HAITI 0x0f
496 #ifndef SUBLANG_GERMAN_LUXEMBOURG
497 #define SUBLANG_GERMAN_LUXEMBOURG 0x04
499 #ifndef SUBLANG_GERMAN_LIECHTENSTEIN
500 #define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
502 #ifndef SUBLANG_KASHMIRI_INDIA
503 #define SUBLANG_KASHMIRI_INDIA 0x02
505 #ifndef SUBLANG_MALAY_MALAYSIA
506 #define SUBLANG_MALAY_MALAYSIA 0x01
508 #ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
509 #define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
511 #ifndef SUBLANG_NEPALI_INDIA
512 #define SUBLANG_NEPALI_INDIA 0x02
514 #ifndef SUBLANG_PUNJABI_INDIA
515 #define SUBLANG_PUNJABI_INDIA 0x00
517 #ifndef SUBLANG_PUNJABI_PAKISTAN
518 #define SUBLANG_PUNJABI_PAKISTAN 0x01
520 #ifndef SUBLANG_ROMANIAN_ROMANIA
521 #define SUBLANG_ROMANIAN_ROMANIA 0x00
523 #ifndef SUBLANG_ROMANIAN_MOLDOVA
524 #define SUBLANG_ROMANIAN_MOLDOVA 0x01
526 #ifndef SUBLANG_SERBIAN_LATIN
527 #define SUBLANG_SERBIAN_LATIN 0x02
529 #ifndef SUBLANG_SERBIAN_CYRILLIC
530 #define SUBLANG_SERBIAN_CYRILLIC 0x03
532 #ifndef SUBLANG_SINDHI_INDIA
533 #define SUBLANG_SINDHI_INDIA 0x00
535 #ifndef SUBLANG_SINDHI_PAKISTAN
536 #define SUBLANG_SINDHI_PAKISTAN 0x01
538 #ifndef SUBLANG_SPANISH_GUATEMALA
539 #define SUBLANG_SPANISH_GUATEMALA 0x04
541 #ifndef SUBLANG_SPANISH_COSTA_RICA
542 #define SUBLANG_SPANISH_COSTA_RICA 0x05
544 #ifndef SUBLANG_SPANISH_PANAMA
545 #define SUBLANG_SPANISH_PANAMA 0x06
547 #ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
548 #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
550 #ifndef SUBLANG_SPANISH_VENEZUELA
551 #define SUBLANG_SPANISH_VENEZUELA 0x08
553 #ifndef SUBLANG_SPANISH_COLOMBIA
554 #define SUBLANG_SPANISH_COLOMBIA 0x09
556 #ifndef SUBLANG_SPANISH_PERU
557 #define SUBLANG_SPANISH_PERU 0x0a
559 #ifndef SUBLANG_SPANISH_ARGENTINA
560 #define SUBLANG_SPANISH_ARGENTINA 0x0b
562 #ifndef SUBLANG_SPANISH_ECUADOR
563 #define SUBLANG_SPANISH_ECUADOR 0x0c
565 #ifndef SUBLANG_SPANISH_CHILE
566 #define SUBLANG_SPANISH_CHILE 0x0d
568 #ifndef SUBLANG_SPANISH_URUGUAY
569 #define SUBLANG_SPANISH_URUGUAY 0x0e
571 #ifndef SUBLANG_SPANISH_PARAGUAY
572 #define SUBLANG_SPANISH_PARAGUAY 0x0f
574 #ifndef SUBLANG_SPANISH_BOLIVIA
575 #define SUBLANG_SPANISH_BOLIVIA 0x10
577 #ifndef SUBLANG_SPANISH_EL_SALVADOR
578 #define SUBLANG_SPANISH_EL_SALVADOR 0x11
580 #ifndef SUBLANG_SPANISH_HONDURAS
581 #define SUBLANG_SPANISH_HONDURAS 0x12
583 #ifndef SUBLANG_SPANISH_NICARAGUA
584 #define SUBLANG_SPANISH_NICARAGUA 0x13
586 #ifndef SUBLANG_SPANISH_PUERTO_RICO
587 #define SUBLANG_SPANISH_PUERTO_RICO 0x14
589 #ifndef SUBLANG_SWEDISH_FINLAND
590 #define SUBLANG_SWEDISH_FINLAND 0x02
592 #ifndef SUBLANG_TAMAZIGHT_ARABIC
593 #define SUBLANG_TAMAZIGHT_ARABIC 0x01
595 #ifndef SUBLANG_TAMAZIGHT_LATIN
596 #define SUBLANG_TAMAZIGHT_LATIN 0x02
598 #ifndef SUBLANG_TIGRINYA_ETHIOPIA
599 #define SUBLANG_TIGRINYA_ETHIOPIA 0x00
601 #ifndef SUBLANG_TIGRINYA_ERITREA
602 #define SUBLANG_TIGRINYA_ERITREA 0x01
604 #ifndef SUBLANG_URDU_PAKISTAN
605 #define SUBLANG_URDU_PAKISTAN 0x01
607 #ifndef SUBLANG_URDU_INDIA
608 #define SUBLANG_URDU_INDIA 0x02
610 #ifndef SUBLANG_UZBEK_LATIN
611 #define SUBLANG_UZBEK_LATIN 0x01
613 #ifndef SUBLANG_UZBEK_CYRILLIC
614 #define SUBLANG_UZBEK_CYRILLIC 0x02
618 g_win32_getlocale (void)
624 gchar *l = "C", *sl = NULL;
627 /* Let the user override the system settings through environment
628 variables, as on POSIX systems. */
629 if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0')
630 || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0')
631 || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0'))
632 return g_strdup (ev);
634 /* Use native Win32 API locale ID. */
635 lcid = GetThreadLocale ();
637 /* Strip off the sorting rules, keep only the language part. */
638 langid = LANGIDFROMLCID (lcid);
640 /* Split into language and territory part. */
641 primary = PRIMARYLANGID (langid);
642 sub = SUBLANGID (langid);
645 case LANG_AFRIKAANS: l = "af"; sl = "ZA"; break;
646 case LANG_ALBANIAN: l = "sq"; sl = "AL"; break;
651 case SUBLANG_ARABIC_SAUDI_ARABIA: sl = "SA"; break;
652 case SUBLANG_ARABIC_IRAQ: sl = "IQ"; break;
653 case SUBLANG_ARABIC_EGYPT: sl = "EG"; break;
654 case SUBLANG_ARABIC_LIBYA: sl = "LY"; break;
655 case SUBLANG_ARABIC_ALGERIA: sl = "DZ"; break;
656 case SUBLANG_ARABIC_MOROCCO: sl = "MA"; break;
657 case SUBLANG_ARABIC_TUNISIA: sl = "TN"; break;
658 case SUBLANG_ARABIC_OMAN: sl = "OM"; break;
659 case SUBLANG_ARABIC_YEMEN: sl = "YE"; break;
660 case SUBLANG_ARABIC_SYRIA: sl = "SY"; break;
661 case SUBLANG_ARABIC_JORDAN: sl = "JO"; break;
662 case SUBLANG_ARABIC_LEBANON: sl = "LB"; break;
663 case SUBLANG_ARABIC_KUWAIT: sl = "KW"; break;
664 case SUBLANG_ARABIC_UAE: sl = "AE"; break;
665 case SUBLANG_ARABIC_BAHRAIN: sl = "BH"; break;
666 case SUBLANG_ARABIC_QATAR: sl = "QA"; break;
669 case LANG_ARMENIAN: l = "hy"; sl = "AM"; break;
670 case LANG_ASSAMESE: l = "as"; sl = "IN"; break;
675 /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
676 case SUBLANG_AZERI_LATIN: sl = "AZ@latin"; break;
677 case SUBLANG_AZERI_CYRILLIC: sl = "AZ@cyrillic"; break;
681 l = "eu"; /* sl could be "ES" or "FR". */
683 case LANG_BELARUSIAN: l = "be"; sl = "BY"; break;
688 case SUBLANG_BENGALI_INDIA: sl = "IN"; break;
689 case SUBLANG_BENGALI_BANGLADESH: sl = "BD"; break;
692 case LANG_BULGARIAN: l = "bg"; sl = "BG"; break;
693 case LANG_BURMESE: l = "my"; sl = "MM"; break;
694 case LANG_CAMBODIAN: l = "km"; sl = "KH"; break;
695 case LANG_CATALAN: l = "ca"; sl = "ES"; break;
700 case SUBLANG_CHINESE_TRADITIONAL: sl = "TW"; break;
701 case SUBLANG_CHINESE_SIMPLIFIED: sl = "CN"; break;
702 case SUBLANG_CHINESE_HONGKONG: sl = "HK"; break;
703 case SUBLANG_CHINESE_SINGAPORE: sl = "SG"; break;
704 case SUBLANG_CHINESE_MACAU: sl = "MO"; break;
707 case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN */
710 /* FIXME: How to distinguish Croatian and Latin Serbian locales? */
711 case SUBLANG_SERBIAN_LATIN: l = "sr"; sl = "@Latn"; break;
712 case SUBLANG_SERBIAN_CYRILLIC: l = "sr"; break;
713 default: l = "hr"; sl = "HR";
716 case LANG_CZECH: l = "cs"; sl = "CZ"; break;
717 case LANG_DANISH: l = "da"; sl = "DK"; break;
718 case LANG_DIVEHI: l = "div"; sl = "MV"; break;
723 case SUBLANG_DUTCH: sl = "NL"; break;
724 case SUBLANG_DUTCH_BELGIAN: sl = "BE"; break;
731 case SUBLANG_ENGLISH_US: sl = "US"; break;
732 case SUBLANG_ENGLISH_UK: sl = "GB"; break;
733 case SUBLANG_ENGLISH_AUS: sl = "AU"; break;
734 case SUBLANG_ENGLISH_CAN: sl = "CA"; break;
735 case SUBLANG_ENGLISH_NZ: sl = "NZ"; break;
736 case SUBLANG_ENGLISH_EIRE: sl = "IE"; break;
737 case SUBLANG_ENGLISH_SOUTH_AFRICA: sl = "ZA"; break;
738 case SUBLANG_ENGLISH_JAMAICA: sl = "JM"; break;
739 case SUBLANG_ENGLISH_CARIBBEAN: sl = "GD"; break; /* Grenada? */
740 case SUBLANG_ENGLISH_BELIZE: sl = "BZ"; break;
741 case SUBLANG_ENGLISH_TRINIDAD: sl = "TT"; break;
742 case SUBLANG_ENGLISH_ZIMBABWE: sl = "ZW"; break;
743 case SUBLANG_ENGLISH_PHILIPPINES: sl = "PH"; break;
744 case SUBLANG_ENGLISH_INDONESIA: sl = "ID"; break;
745 case SUBLANG_ENGLISH_HONGKONG: sl = "HK"; break;
746 case SUBLANG_ENGLISH_INDIA: sl = "IN"; break;
747 case SUBLANG_ENGLISH_MALAYSIA: sl = "MY"; break;
748 case SUBLANG_ENGLISH_SINGAPORE: sl = "SG"; break;
751 case LANG_ESTONIAN: l = "et"; sl = "EE"; break;
752 case LANG_FAEROESE: l = "fo"; sl = "FO"; break;
753 case LANG_FARSI: l = "fa"; sl = "IR"; break;
754 case LANG_FINNISH: l = "fi"; sl = "FI"; break;
759 case SUBLANG_FRENCH: sl = "FR"; break;
760 case SUBLANG_FRENCH_BELGIAN: sl = "BE"; break;
761 case SUBLANG_FRENCH_CANADIAN: sl = "CA"; break;
762 case SUBLANG_FRENCH_SWISS: sl = "CH"; break;
763 case SUBLANG_FRENCH_LUXEMBOURG: sl = "LU"; break;
764 case SUBLANG_FRENCH_MONACO: sl = "MC"; break;
765 case SUBLANG_FRENCH_WESTINDIES: break;
766 case SUBLANG_FRENCH_REUNION: sl = "RE"; break;
767 case SUBLANG_FRENCH_CONGO: sl = "CG"; break;
768 case SUBLANG_FRENCH_SENEGAL: sl = "SN"; break;
769 case SUBLANG_FRENCH_CAMEROON: sl = "CM"; break;
770 case SUBLANG_FRENCH_COTEDIVOIRE: sl = "CI"; break;
771 case SUBLANG_FRENCH_MALI: sl = "ML"; break;
772 case SUBLANG_FRENCH_MOROCCO: sl = "MA"; break;
773 case SUBLANG_FRENCH_HAITI: sl = "HT"; break;
776 case LANG_FRISIAN: l = "fy"; sl ="NL"; break;
777 case LANG_FULFULDE: l = "ful"; sl = "NG"; break;
781 case 0x01: /* SCOTTISH */ l = "gd"; sl = "GB"; break;
782 case 0x02: /* IRISH */ l = "ga"; sl = "IE"; break;
785 case LANG_GALICIAN: l = "gl"; sl = "ES"; break;
786 case LANG_GEORGIAN: l = "ka"; sl = "GE"; break;
791 case SUBLANG_GERMAN: sl = "DE"; break;
792 case SUBLANG_GERMAN_SWISS: sl = "CH"; break;
793 case SUBLANG_GERMAN_AUSTRIAN: sl = "AT"; break;
794 case SUBLANG_GERMAN_LUXEMBOURG: sl = "LU"; break;
795 case SUBLANG_GERMAN_LIECHTENSTEIN: sl = "LI"; break;
798 case LANG_GREEK: l = "el"; sl = "GR"; break;
799 case LANG_GUARANI: l = "gn"; sl = "PY"; break;
800 case LANG_GUJARATI: l = "gu"; sl = "IN"; break;
801 case LANG_HAUSA: l = "ha"; sl = "NG"; break;
803 /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
804 * or Hawaii Creole English ("cpe_US", 600000 speakers)?
809 case LANG_HEBREW: l = "he"; sl = "IL"; break;
810 case LANG_HINDI: l = "hi"; sl = "IN"; break;
811 case LANG_HUNGARIAN: l = "hu"; sl = "HU"; break;
812 case LANG_IBIBIO: l = "nic"; sl = "NG"; break;
813 case LANG_ICELANDIC: l = "is"; sl = "IS"; break;
814 case LANG_IGBO: l = "ibo"; sl = "NG"; break;
815 case LANG_INDONESIAN: l = "id"; sl = "ID"; break;
816 case LANG_INUKTITUT: l = "iu"; sl = "CA"; break;
821 case SUBLANG_ITALIAN: sl = "IT"; break;
822 case SUBLANG_ITALIAN_SWISS: sl = "CH"; break;
825 case LANG_JAPANESE: l = "ja"; sl = "JP"; break;
826 case LANG_KANNADA: l = "kn"; sl = "IN"; break;
827 case LANG_KANURI: l = "kau"; sl = "NG"; break;
832 case SUBLANG_DEFAULT: sl = "PK"; break;
833 case SUBLANG_KASHMIRI_INDIA: sl = "IN"; break;
836 case LANG_KAZAK: l = "kk"; sl = "KZ"; break;
838 /* FIXME: Adjust this when such locales appear on Unix. */
842 case LANG_KOREAN: l = "ko"; sl = "KR"; break;
843 case LANG_KYRGYZ: l = "ky"; sl = "KG"; break;
844 case LANG_LAO: l = "lo"; sl = "LA"; break;
845 case LANG_LATIN: l = "la"; sl = "VA"; break;
846 case LANG_LATVIAN: l = "lv"; sl = "LV"; break;
847 case LANG_LITHUANIAN: l = "lt"; sl = "LT"; break;
848 case LANG_MACEDONIAN: l = "mk"; sl = "MK"; break;
853 case SUBLANG_MALAY_MALAYSIA: sl = "MY"; break;
854 case SUBLANG_MALAY_BRUNEI_DARUSSALAM: sl = "BN"; break;
857 case LANG_MALAYALAM: l = "ml"; sl = "IN"; break;
859 /* FIXME: Adjust this when such locales appear on Unix. */
863 case LANG_MARATHI: l = "mr"; sl = "IN"; break;
865 /* Ambiguous: could be "mn_CN" or "mn_MN". */
872 case SUBLANG_DEFAULT: sl = "NP"; break;
873 case SUBLANG_NEPALI_INDIA: sl = "IN"; break;
880 case SUBLANG_NORWEGIAN_BOKMAL: sl = "NO"; break;
881 case SUBLANG_NORWEGIAN_NYNORSK: l = "nn"; sl = "NO"; break;
884 case LANG_ORIYA: l = "or"; sl = "IN"; break;
885 case LANG_OROMO: l = "om"; sl = "ET"; break;
886 case LANG_PAPIAMENTU: l = "pap"; sl = "AN"; break;
888 /* Ambiguous: could be "ps_PK" or "ps_AF". */
891 case LANG_POLISH: l = "pl"; sl = "PL"; break;
892 case LANG_PORTUGUESE:
896 case SUBLANG_PORTUGUESE: sl = "PT"; break;
897 case SUBLANG_PORTUGUESE_BRAZILIAN: sl = "BR"; break;
904 case SUBLANG_PUNJABI_INDIA: sl = "IN"; break; /* Gurmukhi script */
905 case SUBLANG_PUNJABI_PAKISTAN: sl = "PK"; break; /* Arabic script */
908 case LANG_RHAETO_ROMANCE: l = "rm"; sl = "CH"; break;
913 case SUBLANG_ROMANIAN_ROMANIA: sl = "RO"; break;
914 case SUBLANG_ROMANIAN_MOLDOVA: sl = "MD"; break;
918 l = "ru";/* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
920 case LANG_SAAMI: /* actually Northern Sami */ l = "se"; sl = "NO"; break;
921 case LANG_SANSKRIT: l = "sa"; sl = "IN"; break;
922 case LANG_SINDHI: l = "sd";
925 case SUBLANG_SINDHI_INDIA: sl = "IN"; break;
926 case SUBLANG_SINDHI_PAKISTAN: sl = "PK"; break;
929 case LANG_SINHALESE: l = "si"; sl = "LK"; break;
930 case LANG_SLOVAK: l = "sk"; sl = "SK"; break;
931 case LANG_SLOVENIAN: l = "sl"; sl = "SI"; break;
932 case LANG_SOMALI: l = "so"; sl = "SO"; break;
934 /* FIXME: Adjust this when such locales appear on Unix. */
942 case SUBLANG_SPANISH: sl = "ES"; break;
943 case SUBLANG_SPANISH_MEXICAN: sl = "MX"; break;
944 case SUBLANG_SPANISH_MODERN:
945 sl = "ES@modern"; break; /* not seen on Unix */
946 case SUBLANG_SPANISH_GUATEMALA: sl = "GT"; break;
947 case SUBLANG_SPANISH_COSTA_RICA: sl = "CR"; break;
948 case SUBLANG_SPANISH_PANAMA: sl = "PA"; break;
949 case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: sl = "DO"; break;
950 case SUBLANG_SPANISH_VENEZUELA: sl = "VE"; break;
951 case SUBLANG_SPANISH_COLOMBIA: sl = "CO"; break;
952 case SUBLANG_SPANISH_PERU: sl = "PE"; break;
953 case SUBLANG_SPANISH_ARGENTINA: sl = "AR"; break;
954 case SUBLANG_SPANISH_ECUADOR: sl = "EC"; break;
955 case SUBLANG_SPANISH_CHILE: sl = "CL"; break;
956 case SUBLANG_SPANISH_URUGUAY: sl = "UY"; break;
957 case SUBLANG_SPANISH_PARAGUAY: sl = "PY"; break;
958 case SUBLANG_SPANISH_BOLIVIA: sl = "BO"; break;
959 case SUBLANG_SPANISH_EL_SALVADOR: sl = "SV"; break;
960 case SUBLANG_SPANISH_HONDURAS: sl = "HN"; break;
961 case SUBLANG_SPANISH_NICARAGUA: sl = "NI"; break;
962 case SUBLANG_SPANISH_PUERTO_RICO: sl = "PR"; break;
965 case LANG_SUTU: l = "bnt"; sl = "TZ"; break; /* or "st_LS" or "nso_ZA"? */
966 case LANG_SWAHILI: l = "sw"; sl = "KE"; break;
971 case SUBLANG_DEFAULT: sl = "SE"; break;
972 case SUBLANG_SWEDISH_FINLAND: sl = "FI"; break;
975 case LANG_SYRIAC: l = "syr"; sl = "TR"; break; /* An extinct language. */
976 case LANG_TAGALOG: l = "tl"; sl = "PH"; break;
977 case LANG_TAJIK: l = "tg"; sl = "TJ"; break;
979 l = "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
981 case LANG_TATAR: l = "tt"; sl = "RU"; break;
982 case LANG_TELUGU: l = "te"; sl = "IN"; break;
983 case LANG_THAI: l = "th"; sl = "TH"; break;
984 case LANG_TIBETAN: l = "bo"; sl = "CN"; break;
989 case SUBLANG_TIGRINYA_ETHIOPIA: sl = "ET"; break;
990 case SUBLANG_TIGRINYA_ERITREA: sl = "ER"; break;
993 case LANG_TSONGA: l = "ts"; sl = "ZA"; break;
994 case LANG_TSWANA: l = "tn"; sl = "BW"; break;
995 case LANG_TURKISH: l = "tr"; sl = "TR"; break;
996 case LANG_TURKMEN: l = "tk"; sl = "TM"; break;
997 case LANG_UKRAINIAN: l = "uk"; sl = "UA"; break;
1002 case SUBLANG_URDU_PAKISTAN: sl = "PK"; break;
1003 case SUBLANG_URDU_INDIA: sl = "IN"; break;
1010 case SUBLANG_UZBEK_LATIN: sl = "UZ"; break;
1011 case SUBLANG_UZBEK_CYRILLIC: sl = "UZ@cyrillic"; break;
1015 /* FIXME: It's not clear whether Venda has the ISO 639-2 two-letter code
1017 http://www.loc.gov/standards/iso639-2/englangn.html has it, but
1018 http://lcweb.loc.gov/standards/iso639-2/codechanges.html doesn't, */
1019 l = "ven"; /* or "ve"? */
1022 case LANG_VIETNAMESE: l = "vi"; sl = "VN"; break;
1023 case LANG_WELSH: l = "cy"; sl = "GB"; break;
1024 case LANG_XHOSA: l = "xh"; sl = "ZA"; break;
1025 case LANG_YI: l = "sit"; sl = "CN"; break;
1026 case LANG_YIDDISH: l = "yi"; sl = "IL"; break;
1027 case LANG_YORUBA: l = "yo"; sl = "NG"; break;
1028 case LANG_ZULU: l = "zu"; sl = "ZA"; break;
1038 return g_strdup (bfr);
1042 * g_win32_error_message:
1043 * @error: error code.
1045 * Translate a Win32 error code (as returned by GetLastError()) into
1046 * the corresponding message. The message is either language neutral,
1047 * or in the thread's language, or the user's language, the system's
1048 * language, or US English (see docs for FormatMessage()). The
1049 * returned string is in UTF-8. It should be deallocated with
1052 * Returns: newly-allocated error message
1055 g_win32_error_message (gint error)
1059 if (G_WIN32_HAVE_WIDECHAR_API ())
1061 wchar_t *msg = NULL;
1064 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER
1065 |FORMAT_MESSAGE_IGNORE_INSERTS
1066 |FORMAT_MESSAGE_FROM_SYSTEM,
1068 (LPWSTR) &msg, 0, NULL);
1071 nchars = wcslen (msg);
1073 if (nchars > 2 && msg[nchars-1] == '\n' && msg[nchars-2] == '\r')
1074 msg[nchars-2] = '\0';
1076 retval = g_utf16_to_utf8 (msg, -1, NULL, NULL, NULL);
1081 retval = g_strdup ("");
1088 FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER
1089 |FORMAT_MESSAGE_IGNORE_INSERTS
1090 |FORMAT_MESSAGE_FROM_SYSTEM,
1092 (LPTSTR) &msg, 0, NULL);
1095 nbytes = strlen (msg);
1097 if (nbytes > 2 && msg[nbytes-1] == '\n' && msg[nbytes-2] == '\r')
1098 msg[nbytes-2] = '\0';
1100 retval = g_locale_to_utf8 (msg, -1, NULL, NULL, NULL);
1105 retval = g_strdup ("");
1112 get_package_directory_from_module (gchar *module_name)
1114 static GHashTable *module_dirs = NULL;
1115 G_LOCK_DEFINE_STATIC (module_dirs);
1116 HMODULE hmodule = NULL;
1121 G_LOCK (module_dirs);
1123 if (module_dirs == NULL)
1124 module_dirs = g_hash_table_new (g_str_hash, g_str_equal);
1126 result = g_hash_table_lookup (module_dirs, module_name ? module_name : "");
1130 G_UNLOCK (module_dirs);
1131 return g_strdup (result);
1136 if (G_WIN32_HAVE_WIDECHAR_API ())
1138 wchar_t *wc_module_name = g_utf8_to_utf16 (module_name, -1, NULL, NULL, NULL);
1139 hmodule = GetModuleHandleW (wc_module_name);
1140 g_free (wc_module_name);
1144 char *cp_module_name = g_locale_from_utf8 (module_name, -1, NULL, NULL, NULL);
1145 hmodule = GetModuleHandleA (cp_module_name);
1146 g_free (cp_module_name);
1152 if (G_WIN32_HAVE_WIDECHAR_API ())
1154 wchar_t wc_fn[MAX_PATH];
1155 if (!GetModuleFileNameW (hmodule, wc_fn, MAX_PATH))
1157 G_UNLOCK (module_dirs);
1160 fn = g_utf16_to_utf8 (wc_fn, -1, NULL, NULL, NULL);
1164 gchar cp_fn[MAX_PATH];
1165 if (!GetModuleFileNameA (hmodule, cp_fn, MAX_PATH))
1167 G_UNLOCK (module_dirs);
1170 fn = g_locale_to_utf8 (cp_fn, -1, NULL, NULL, NULL);
1173 if ((p = strrchr (fn, G_DIR_SEPARATOR)) != NULL)
1176 p = strrchr (fn, G_DIR_SEPARATOR);
1177 if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0 ||
1178 g_ascii_strcasecmp (p + 1, "lib") == 0))
1181 #ifdef G_WITH_CYGWIN
1182 /* In Cygwin we need to have POSIX paths */
1184 gchar tmp[MAX_PATH];
1186 cygwin_conv_to_posix_path(fn, tmp);
1192 g_hash_table_insert (module_dirs, module_name ? module_name : "", fn);
1194 G_UNLOCK (module_dirs);
1196 return g_strdup (fn);
1200 * g_win32_get_package_installation_directory:
1201 * @package: An identifier for a software package, or %NULL, in UTF-8
1202 * @dll_name: The name of a DLL that a package provides, or %NULL, in UTF-8
1204 * Try to determine the installation directory for a software package.
1205 * Typically used by GNU software packages.
1207 * @package should be a short identifier for the package. Typically it
1208 * is the same identifier as used for
1209 * <literal>GETTEXT_PACKAGE</literal> in software configured according
1210 * to GNU standards. The function first looks in the Windows Registry
1211 * for the value <literal>#InstallationDirectory</literal> in the key
1212 * <literal>#HKLM\Software\@package</literal>, and if that value
1213 * exists and is a string, returns that.
1215 * If @package is %NULL, or the above value isn't found in the
1216 * Registry, but @dll_name is non-%NULL, it should name a DLL loaded
1217 * into the current process. Typically that would be the name of the
1218 * DLL calling this function, looking for its installation
1219 * directory. The function then asks Windows what directory that DLL
1220 * was loaded from. If that directory's last component is "bin" or
1221 * "lib", the parent directory is returned, otherwise the directory
1222 * itself. If that DLL isn't loaded, the function proceeds as if
1223 * @dll_name was %NULL.
1225 * If both @package and @dll_name are %NULL, the directory from where
1226 * the main executable of the process was loaded is used instead in
1227 * the same way as above.
1229 * Returns: a string containing the installation directory for
1230 * @package. The string is in the GLib file name encoding, i.e. UTF-8
1231 * on Windows. The return value should be freed with g_free() when not
1232 * needed any longer.
1236 g_win32_get_package_installation_directory (gchar *package,
1239 static GHashTable *package_dirs = NULL;
1240 G_LOCK_DEFINE_STATIC (package_dirs);
1241 gchar *result = NULL;
1243 HKEY reg_key = NULL;
1247 if (package != NULL)
1249 G_LOCK (package_dirs);
1251 if (package_dirs == NULL)
1252 package_dirs = g_hash_table_new (g_str_hash, g_str_equal);
1254 result = g_hash_table_lookup (package_dirs, package);
1256 if (result && result[0])
1258 G_UNLOCK (package_dirs);
1259 return g_strdup (result);
1262 key = g_strconcat ("Software\\", package, NULL);
1265 if (G_WIN32_HAVE_WIDECHAR_API ())
1267 wchar_t *wc_key = g_utf8_to_utf16 (key, -1, NULL, NULL, NULL);
1268 if (((RegOpenKeyExW (HKEY_CURRENT_USER, wc_key, 0,
1269 KEY_QUERY_VALUE, ®_key) == ERROR_SUCCESS
1270 && RegQueryValueExW (reg_key, L"InstallationDirectory", 0,
1271 &type, NULL, &nbytes) == ERROR_SUCCESS)
1273 (RegOpenKeyExW (HKEY_LOCAL_MACHINE, wc_key, 0,
1274 KEY_QUERY_VALUE, ®_key) == ERROR_SUCCESS
1275 && RegQueryValueExW (reg_key, L"InstallationDirectory", 0,
1276 &type, NULL, &nbytes) == ERROR_SUCCESS))
1279 wchar_t *wc_temp = g_new (wchar_t, (nbytes+1)/2 + 1);
1280 RegQueryValueExW (reg_key, L"InstallationDirectory", 0,
1281 &type, (LPBYTE) wc_temp, &nbytes);
1282 wc_temp[nbytes/2] = '\0';
1283 result = g_utf16_to_utf8 (wc_temp, -1, NULL, NULL, NULL);
1290 char *cp_key = g_locale_from_utf8 (key, -1, NULL, NULL, NULL);
1291 if (((RegOpenKeyExA (HKEY_CURRENT_USER, cp_key, 0,
1292 KEY_QUERY_VALUE, ®_key) == ERROR_SUCCESS
1293 && RegQueryValueExA (reg_key, "InstallationDirectory", 0,
1294 &type, NULL, &nbytes) == ERROR_SUCCESS)
1296 (RegOpenKeyExA (HKEY_LOCAL_MACHINE, cp_key, 0,
1297 KEY_QUERY_VALUE, ®_key) == ERROR_SUCCESS
1298 && RegQueryValueExA (reg_key, "InstallationDirectory", 0,
1299 &type, NULL, &nbytes) == ERROR_SUCCESS))
1302 char *cp_temp = g_malloc (nbytes + 1);
1303 RegQueryValueExA (reg_key, "InstallationDirectory", 0,
1304 &type, cp_temp, &nbytes);
1305 cp_temp[nbytes] = '\0';
1306 result = g_locale_to_utf8 (cp_temp, -1, NULL, NULL, NULL);
1312 if (reg_key != NULL)
1313 RegCloseKey (reg_key);
1319 g_hash_table_insert (package_dirs, package, result);
1320 G_UNLOCK (package_dirs);
1323 G_UNLOCK (package_dirs);
1326 if (dll_name != NULL)
1327 result = get_package_directory_from_module (dll_name);
1330 result = get_package_directory_from_module (NULL);
1335 #undef g_win32_get_package_installation_directory
1337 /* DLL ABI binary compatibility version that uses system codepage file names */
1340 g_win32_get_package_installation_directory (gchar *package,
1343 gchar *utf8_package = NULL, *utf8_dll_name = NULL;
1344 gchar *utf8_retval, *retval;
1346 if (package != NULL)
1347 utf8_package = g_locale_to_utf8 (package, -1, NULL, NULL, NULL);
1349 if (dll_name != NULL)
1350 utf8_dll_name = g_locale_to_utf8 (dll_name, -1, NULL, NULL, NULL);
1353 g_win32_get_package_installation_directory_utf8 (utf8_package,
1356 retval = g_locale_from_utf8 (utf8_retval, -1, NULL, NULL, NULL);
1358 g_free (utf8_package);
1359 g_free (utf8_dll_name);
1360 g_free (utf8_retval);
1366 * g_win32_get_package_installation_subdirectory:
1367 * @package: An identifier for a software package, in UTF-8, or %NULL
1368 * @dll_name: The name of a DLL that a package provides, in UTF-8, or %NULL
1369 * @subdir: A subdirectory of the package installation directory, also in UTF-8
1371 * Returns a newly-allocated string containing the path of the
1372 * subdirectory @subdir in the return value from calling
1373 * g_win32_get_package_installation_directory() with the @package and
1374 * @dll_name parameters.
1376 * Returns: a string containing the complete path to @subdir inside
1377 * the installation directory of @package. The returned string is in
1378 * the GLib file name encoding, i.e. UTF-8 on Windows. The return
1379 * value should be freed with g_free() when no longer needed.
1383 g_win32_get_package_installation_subdirectory (gchar *package,
1390 prefix = g_win32_get_package_installation_directory_utf8 (package, dll_name);
1392 dirname = g_build_filename (prefix, subdir, NULL);
1398 #undef g_win32_get_package_installation_subdirectory
1400 /* DLL ABI binary compatibility version that uses system codepage file names */
1403 g_win32_get_package_installation_subdirectory (gchar *package,
1410 prefix = g_win32_get_package_installation_directory (package, dll_name);
1412 dirname = g_build_filename (prefix, subdir, NULL);
1418 static guint windows_version;
1421 g_win32_windows_version_init (void)
1423 static gboolean beenhere = FALSE;
1428 if (getenv ("G_WIN32_PRETEND_WIN9X"))
1429 windows_version = 0x80000004;
1431 windows_version = GetVersion ();
1436 _g_win32_thread_init (void)
1438 g_win32_windows_version_init ();
1442 * g_win32_get_windows_version:
1444 * Returns version information for the Windows operating system the
1445 * code is running on. See MSDN documentation for the GetVersion()
1446 * function. To summarize, the most significant bit is one on Win9x,
1447 * and zero on NT-based systems. The least significant byte is 4 on
1448 * Windows NT 4, 5 on Windows XP. Software that needs really detailled
1449 * version and feature information should use Win32 API like
1450 * GetVersionEx() and VerifyVersionInfo().
1452 * If there is an environment variable <envar>G_WIN32_PRETEND_WIN9X</envar>
1453 * defined (with any value), this function always returns a version
1454 * code for Windows 9x. This is mainly an internal debugging aid for
1455 * GTK+ and GLib developers, to be able to check the code paths for
1458 * Returns: The version information.
1463 g_win32_get_windows_version (void)
1465 g_win32_windows_version_init ();
1467 return windows_version;
1471 * g_win32_locale_filename_from_utf8:
1472 * @utf8filename: a UTF-8 encoded filename.
1474 * Converts a filename from UTF-8 to the system codepage.
1476 * On NT-based Windows, on NTFS file systems, file names are in
1477 * Unicode. It is quite possible that Unicode file names contain
1478 * characters not representable in the system codepage. (For instance,
1479 * Greek or Cyrillic characters on Western European or US Windows
1480 * installations, or various less common CJK characters on CJK Windows
1483 * In such a case, and if the filename refers to an existing file, and
1484 * the file system stores alternate short (8.3) names for directory
1485 * entries, the short form of the filename is returned. Note that the
1486 * "short" name might in fact be longer than the Unicode name if the
1487 * Unicode name has very short pathname components containing
1488 * non-ASCII characters. If no system codepage name for the file is
1489 * possible, %NULL is returned.
1491 * The return value is dynamically allocated and should be freed with
1492 * g_free() when no longer needed.
1494 * Return value: The converted filename, or %NULL on conversion
1495 * failure and lack of short names.
1500 g_win32_locale_filename_from_utf8 (const gchar *utf8filename)
1502 gchar *retval = g_locale_from_utf8 (utf8filename, -1, NULL, NULL, NULL);
1504 if (retval == NULL && G_WIN32_HAVE_WIDECHAR_API ())
1506 /* Conversion failed, so convert to wide chars, check if there
1507 * is a 8.3 version, and use that.
1509 wchar_t *wname = g_utf8_to_utf16 (utf8filename, -1, NULL, NULL, NULL);
1512 wchar_t wshortname[MAX_PATH + 1];
1513 if (GetShortPathNameW (wname, wshortname, G_N_ELEMENTS (wshortname)))
1515 gchar *tem = g_utf16_to_utf8 (wshortname, -1, NULL, NULL, NULL);
1516 retval = g_locale_from_utf8 (tem, -1, NULL, NULL, NULL);
1525 #define __G_WIN32_C__
1526 #include "galiasdef.c"