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.
35 #include "glibconfig.h"
42 #define STRICT /* Strict typing, please */
57 #include <sys/cygwin.h>
63 g_win32_ftruncate (gint fd,
66 return _chsize (fd, size);
74 * The setlocale in the Microsoft C library uses locale names of the
75 * form "English_United States.1252" etc. We want the UNIXish standard
76 * form "en_US", "zh_TW" etc. This function gets the current thread
77 * locale from Windows - without any encoding info - and returns it as
78 * a string of the above form for use in forming file names etc. The
79 * returned string should be deallocated with g_free().
81 * Returns: newly-allocated locale name.
84 /* Borrowed from GNU gettext 0.13.1: */
85 /* Mingw headers don't have latest language and sublanguage codes. */
86 #ifndef LANG_AFRIKAANS
87 #define LANG_AFRIKAANS 0x36
90 #define LANG_ALBANIAN 0x1c
93 #define LANG_AMHARIC 0x5e
96 #define LANG_ARABIC 0x01
99 #define LANG_ARMENIAN 0x2b
101 #ifndef LANG_ASSAMESE
102 #define LANG_ASSAMESE 0x4d
105 #define LANG_AZERI 0x2c
108 #define LANG_BASQUE 0x2d
110 #ifndef LANG_BELARUSIAN
111 #define LANG_BELARUSIAN 0x23
114 #define LANG_BENGALI 0x45
117 #define LANG_BURMESE 0x55
119 #ifndef LANG_CAMBODIAN
120 #define LANG_CAMBODIAN 0x53
123 #define LANG_CATALAN 0x03
125 #ifndef LANG_CHEROKEE
126 #define LANG_CHEROKEE 0x5c
129 #define LANG_DIVEHI 0x65
132 #define LANG_EDO 0x66
134 #ifndef LANG_ESTONIAN
135 #define LANG_ESTONIAN 0x25
137 #ifndef LANG_FAEROESE
138 #define LANG_FAEROESE 0x38
141 #define LANG_FARSI 0x29
144 #define LANG_FRISIAN 0x62
146 #ifndef LANG_FULFULDE
147 #define LANG_FULFULDE 0x67
150 #define LANG_GAELIC 0x3c
152 #ifndef LANG_GALICIAN
153 #define LANG_GALICIAN 0x56
155 #ifndef LANG_GEORGIAN
156 #define LANG_GEORGIAN 0x37
159 #define LANG_GUARANI 0x74
161 #ifndef LANG_GUJARATI
162 #define LANG_GUJARATI 0x47
165 #define LANG_HAUSA 0x68
167 #ifndef LANG_HAWAIIAN
168 #define LANG_HAWAIIAN 0x75
171 #define LANG_HEBREW 0x0d
174 #define LANG_HINDI 0x39
177 #define LANG_IBIBIO 0x69
180 #define LANG_IGBO 0x70
182 #ifndef LANG_INDONESIAN
183 #define LANG_INDONESIAN 0x21
185 #ifndef LANG_INUKTITUT
186 #define LANG_INUKTITUT 0x5d
189 #define LANG_KANNADA 0x4b
192 #define LANG_KANURI 0x71
194 #ifndef LANG_KASHMIRI
195 #define LANG_KASHMIRI 0x60
198 #define LANG_KAZAK 0x3f
201 #define LANG_KONKANI 0x57
204 #define LANG_KYRGYZ 0x40
207 #define LANG_LAO 0x54
210 #define LANG_LATIN 0x76
213 #define LANG_LATVIAN 0x26
215 #ifndef LANG_LITHUANIAN
216 #define LANG_LITHUANIAN 0x27
218 #ifndef LANG_MACEDONIAN
219 #define LANG_MACEDONIAN 0x2f
222 #define LANG_MALAY 0x3e
224 #ifndef LANG_MALAYALAM
225 #define LANG_MALAYALAM 0x4c
228 #define LANG_MALTESE 0x3a
230 #ifndef LANG_MANIPURI
231 #define LANG_MANIPURI 0x58
234 #define LANG_MARATHI 0x4e
236 #ifndef LANG_MONGOLIAN
237 #define LANG_MONGOLIAN 0x50
240 #define LANG_NEPALI 0x61
243 #define LANG_ORIYA 0x48
246 #define LANG_OROMO 0x72
248 #ifndef LANG_PAPIAMENTU
249 #define LANG_PAPIAMENTU 0x79
252 #define LANG_PASHTO 0x63
255 #define LANG_PUNJABI 0x46
257 #ifndef LANG_RHAETO_ROMANCE
258 #define LANG_RHAETO_ROMANCE 0x17
261 #define LANG_SAAMI 0x3b
263 #ifndef LANG_SANSKRIT
264 #define LANG_SANSKRIT 0x4f
267 #define LANG_SERBIAN 0x1a
270 #define LANG_SINDHI 0x59
272 #ifndef LANG_SINHALESE
273 #define LANG_SINHALESE 0x5b
276 #define LANG_SLOVAK 0x1b
279 #define LANG_SOMALI 0x77
282 #define LANG_SORBIAN 0x2e
285 #define LANG_SUTU 0x30
288 #define LANG_SWAHILI 0x41
291 #define LANG_SYRIAC 0x5a
294 #define LANG_TAGALOG 0x64
297 #define LANG_TAJIK 0x28
299 #ifndef LANG_TAMAZIGHT
300 #define LANG_TAMAZIGHT 0x5f
303 #define LANG_TAMIL 0x49
306 #define LANG_TATAR 0x44
309 #define LANG_TELUGU 0x4a
312 #define LANG_THAI 0x1e
315 #define LANG_TIBETAN 0x51
317 #ifndef LANG_TIGRINYA
318 #define LANG_TIGRINYA 0x73
321 #define LANG_TSONGA 0x31
324 #define LANG_TSWANA 0x32
327 #define LANG_TURKMEN 0x42
329 #ifndef LANG_UKRAINIAN
330 #define LANG_UKRAINIAN 0x22
333 #define LANG_URDU 0x20
336 #define LANG_UZBEK 0x43
339 #define LANG_VENDA 0x33
341 #ifndef LANG_VIETNAMESE
342 #define LANG_VIETNAMESE 0x2a
345 #define LANG_WELSH 0x52
348 #define LANG_XHOSA 0x34
354 #define LANG_YIDDISH 0x3d
357 #define LANG_YORUBA 0x6a
360 #define LANG_ZULU 0x35
362 #ifndef SUBLANG_ARABIC_SAUDI_ARABIA
363 #define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
365 #ifndef SUBLANG_ARABIC_IRAQ
366 #define SUBLANG_ARABIC_IRAQ 0x02
368 #ifndef SUBLANG_ARABIC_EGYPT
369 #define SUBLANG_ARABIC_EGYPT 0x03
371 #ifndef SUBLANG_ARABIC_LIBYA
372 #define SUBLANG_ARABIC_LIBYA 0x04
374 #ifndef SUBLANG_ARABIC_ALGERIA
375 #define SUBLANG_ARABIC_ALGERIA 0x05
377 #ifndef SUBLANG_ARABIC_MOROCCO
378 #define SUBLANG_ARABIC_MOROCCO 0x06
380 #ifndef SUBLANG_ARABIC_TUNISIA
381 #define SUBLANG_ARABIC_TUNISIA 0x07
383 #ifndef SUBLANG_ARABIC_OMAN
384 #define SUBLANG_ARABIC_OMAN 0x08
386 #ifndef SUBLANG_ARABIC_YEMEN
387 #define SUBLANG_ARABIC_YEMEN 0x09
389 #ifndef SUBLANG_ARABIC_SYRIA
390 #define SUBLANG_ARABIC_SYRIA 0x0a
392 #ifndef SUBLANG_ARABIC_JORDAN
393 #define SUBLANG_ARABIC_JORDAN 0x0b
395 #ifndef SUBLANG_ARABIC_LEBANON
396 #define SUBLANG_ARABIC_LEBANON 0x0c
398 #ifndef SUBLANG_ARABIC_KUWAIT
399 #define SUBLANG_ARABIC_KUWAIT 0x0d
401 #ifndef SUBLANG_ARABIC_UAE
402 #define SUBLANG_ARABIC_UAE 0x0e
404 #ifndef SUBLANG_ARABIC_BAHRAIN
405 #define SUBLANG_ARABIC_BAHRAIN 0x0f
407 #ifndef SUBLANG_ARABIC_QATAR
408 #define SUBLANG_ARABIC_QATAR 0x10
410 #ifndef SUBLANG_AZERI_LATIN
411 #define SUBLANG_AZERI_LATIN 0x01
413 #ifndef SUBLANG_AZERI_CYRILLIC
414 #define SUBLANG_AZERI_CYRILLIC 0x02
416 #ifndef SUBLANG_BENGALI_INDIA
417 #define SUBLANG_BENGALI_INDIA 0x00
419 #ifndef SUBLANG_BENGALI_BANGLADESH
420 #define SUBLANG_BENGALI_BANGLADESH 0x01
422 #ifndef SUBLANG_CHINESE_MACAU
423 #define SUBLANG_CHINESE_MACAU 0x05
425 #ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
426 #define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
428 #ifndef SUBLANG_ENGLISH_JAMAICA
429 #define SUBLANG_ENGLISH_JAMAICA 0x08
431 #ifndef SUBLANG_ENGLISH_CARIBBEAN
432 #define SUBLANG_ENGLISH_CARIBBEAN 0x09
434 #ifndef SUBLANG_ENGLISH_BELIZE
435 #define SUBLANG_ENGLISH_BELIZE 0x0a
437 #ifndef SUBLANG_ENGLISH_TRINIDAD
438 #define SUBLANG_ENGLISH_TRINIDAD 0x0b
440 #ifndef SUBLANG_ENGLISH_ZIMBABWE
441 #define SUBLANG_ENGLISH_ZIMBABWE 0x0c
443 #ifndef SUBLANG_ENGLISH_PHILIPPINES
444 #define SUBLANG_ENGLISH_PHILIPPINES 0x0d
446 #ifndef SUBLANG_ENGLISH_INDONESIA
447 #define SUBLANG_ENGLISH_INDONESIA 0x0e
449 #ifndef SUBLANG_ENGLISH_HONGKONG
450 #define SUBLANG_ENGLISH_HONGKONG 0x0f
452 #ifndef SUBLANG_ENGLISH_INDIA
453 #define SUBLANG_ENGLISH_INDIA 0x10
455 #ifndef SUBLANG_ENGLISH_MALAYSIA
456 #define SUBLANG_ENGLISH_MALAYSIA 0x11
458 #ifndef SUBLANG_ENGLISH_SINGAPORE
459 #define SUBLANG_ENGLISH_SINGAPORE 0x12
461 #ifndef SUBLANG_FRENCH_LUXEMBOURG
462 #define SUBLANG_FRENCH_LUXEMBOURG 0x05
464 #ifndef SUBLANG_FRENCH_MONACO
465 #define SUBLANG_FRENCH_MONACO 0x06
467 #ifndef SUBLANG_FRENCH_WESTINDIES
468 #define SUBLANG_FRENCH_WESTINDIES 0x07
470 #ifndef SUBLANG_FRENCH_REUNION
471 #define SUBLANG_FRENCH_REUNION 0x08
473 #ifndef SUBLANG_FRENCH_CONGO
474 #define SUBLANG_FRENCH_CONGO 0x09
476 #ifndef SUBLANG_FRENCH_SENEGAL
477 #define SUBLANG_FRENCH_SENEGAL 0x0a
479 #ifndef SUBLANG_FRENCH_CAMEROON
480 #define SUBLANG_FRENCH_CAMEROON 0x0b
482 #ifndef SUBLANG_FRENCH_COTEDIVOIRE
483 #define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
485 #ifndef SUBLANG_FRENCH_MALI
486 #define SUBLANG_FRENCH_MALI 0x0d
488 #ifndef SUBLANG_FRENCH_MOROCCO
489 #define SUBLANG_FRENCH_MOROCCO 0x0e
491 #ifndef SUBLANG_FRENCH_HAITI
492 #define SUBLANG_FRENCH_HAITI 0x0f
494 #ifndef SUBLANG_GERMAN_LUXEMBOURG
495 #define SUBLANG_GERMAN_LUXEMBOURG 0x04
497 #ifndef SUBLANG_GERMAN_LIECHTENSTEIN
498 #define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
500 #ifndef SUBLANG_KASHMIRI_INDIA
501 #define SUBLANG_KASHMIRI_INDIA 0x02
503 #ifndef SUBLANG_MALAY_MALAYSIA
504 #define SUBLANG_MALAY_MALAYSIA 0x01
506 #ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
507 #define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
509 #ifndef SUBLANG_NEPALI_INDIA
510 #define SUBLANG_NEPALI_INDIA 0x02
512 #ifndef SUBLANG_PUNJABI_INDIA
513 #define SUBLANG_PUNJABI_INDIA 0x00
515 #ifndef SUBLANG_PUNJABI_PAKISTAN
516 #define SUBLANG_PUNJABI_PAKISTAN 0x01
518 #ifndef SUBLANG_ROMANIAN_ROMANIA
519 #define SUBLANG_ROMANIAN_ROMANIA 0x00
521 #ifndef SUBLANG_ROMANIAN_MOLDOVA
522 #define SUBLANG_ROMANIAN_MOLDOVA 0x01
524 #ifndef SUBLANG_SERBIAN_LATIN
525 #define SUBLANG_SERBIAN_LATIN 0x02
527 #ifndef SUBLANG_SERBIAN_CYRILLIC
528 #define SUBLANG_SERBIAN_CYRILLIC 0x03
530 #ifndef SUBLANG_SINDHI_INDIA
531 #define SUBLANG_SINDHI_INDIA 0x00
533 #ifndef SUBLANG_SINDHI_PAKISTAN
534 #define SUBLANG_SINDHI_PAKISTAN 0x01
536 #ifndef SUBLANG_SPANISH_GUATEMALA
537 #define SUBLANG_SPANISH_GUATEMALA 0x04
539 #ifndef SUBLANG_SPANISH_COSTA_RICA
540 #define SUBLANG_SPANISH_COSTA_RICA 0x05
542 #ifndef SUBLANG_SPANISH_PANAMA
543 #define SUBLANG_SPANISH_PANAMA 0x06
545 #ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
546 #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
548 #ifndef SUBLANG_SPANISH_VENEZUELA
549 #define SUBLANG_SPANISH_VENEZUELA 0x08
551 #ifndef SUBLANG_SPANISH_COLOMBIA
552 #define SUBLANG_SPANISH_COLOMBIA 0x09
554 #ifndef SUBLANG_SPANISH_PERU
555 #define SUBLANG_SPANISH_PERU 0x0a
557 #ifndef SUBLANG_SPANISH_ARGENTINA
558 #define SUBLANG_SPANISH_ARGENTINA 0x0b
560 #ifndef SUBLANG_SPANISH_ECUADOR
561 #define SUBLANG_SPANISH_ECUADOR 0x0c
563 #ifndef SUBLANG_SPANISH_CHILE
564 #define SUBLANG_SPANISH_CHILE 0x0d
566 #ifndef SUBLANG_SPANISH_URUGUAY
567 #define SUBLANG_SPANISH_URUGUAY 0x0e
569 #ifndef SUBLANG_SPANISH_PARAGUAY
570 #define SUBLANG_SPANISH_PARAGUAY 0x0f
572 #ifndef SUBLANG_SPANISH_BOLIVIA
573 #define SUBLANG_SPANISH_BOLIVIA 0x10
575 #ifndef SUBLANG_SPANISH_EL_SALVADOR
576 #define SUBLANG_SPANISH_EL_SALVADOR 0x11
578 #ifndef SUBLANG_SPANISH_HONDURAS
579 #define SUBLANG_SPANISH_HONDURAS 0x12
581 #ifndef SUBLANG_SPANISH_NICARAGUA
582 #define SUBLANG_SPANISH_NICARAGUA 0x13
584 #ifndef SUBLANG_SPANISH_PUERTO_RICO
585 #define SUBLANG_SPANISH_PUERTO_RICO 0x14
587 #ifndef SUBLANG_SWEDISH_FINLAND
588 #define SUBLANG_SWEDISH_FINLAND 0x02
590 #ifndef SUBLANG_TAMAZIGHT_ARABIC
591 #define SUBLANG_TAMAZIGHT_ARABIC 0x01
593 #ifndef SUBLANG_TAMAZIGHT_LATIN
594 #define SUBLANG_TAMAZIGHT_LATIN 0x02
596 #ifndef SUBLANG_TIGRINYA_ETHIOPIA
597 #define SUBLANG_TIGRINYA_ETHIOPIA 0x00
599 #ifndef SUBLANG_TIGRINYA_ERITREA
600 #define SUBLANG_TIGRINYA_ERITREA 0x01
602 #ifndef SUBLANG_URDU_PAKISTAN
603 #define SUBLANG_URDU_PAKISTAN 0x01
605 #ifndef SUBLANG_URDU_INDIA
606 #define SUBLANG_URDU_INDIA 0x02
608 #ifndef SUBLANG_UZBEK_LATIN
609 #define SUBLANG_UZBEK_LATIN 0x01
611 #ifndef SUBLANG_UZBEK_CYRILLIC
612 #define SUBLANG_UZBEK_CYRILLIC 0x02
616 g_win32_getlocale (void)
622 gchar *l = "C", *sl = NULL;
625 /* Let the user override the system settings through environment
626 variables, as on POSIX systems. */
627 if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0')
628 || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0')
629 || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0'))
630 return g_strdup (ev);
632 /* Use native Win32 API locale ID. */
633 lcid = GetThreadLocale ();
635 /* Strip off the sorting rules, keep only the language part. */
636 langid = LANGIDFROMLCID (lcid);
638 /* Split into language and territory part. */
639 primary = PRIMARYLANGID (langid);
640 sub = SUBLANGID (langid);
643 case LANG_AFRIKAANS: l = "af"; sl = "ZA"; break;
644 case LANG_ALBANIAN: l = "sq"; sl = "AL"; break;
649 case SUBLANG_ARABIC_SAUDI_ARABIA: sl = "SA"; break;
650 case SUBLANG_ARABIC_IRAQ: sl = "IQ"; break;
651 case SUBLANG_ARABIC_EGYPT: sl = "EG"; break;
652 case SUBLANG_ARABIC_LIBYA: sl = "LY"; break;
653 case SUBLANG_ARABIC_ALGERIA: sl = "DZ"; break;
654 case SUBLANG_ARABIC_MOROCCO: sl = "MA"; break;
655 case SUBLANG_ARABIC_TUNISIA: sl = "TN"; break;
656 case SUBLANG_ARABIC_OMAN: sl = "OM"; break;
657 case SUBLANG_ARABIC_YEMEN: sl = "YE"; break;
658 case SUBLANG_ARABIC_SYRIA: sl = "SY"; break;
659 case SUBLANG_ARABIC_JORDAN: sl = "JO"; break;
660 case SUBLANG_ARABIC_LEBANON: sl = "LB"; break;
661 case SUBLANG_ARABIC_KUWAIT: sl = "KW"; break;
662 case SUBLANG_ARABIC_UAE: sl = "AE"; break;
663 case SUBLANG_ARABIC_BAHRAIN: sl = "BH"; break;
664 case SUBLANG_ARABIC_QATAR: sl = "QA"; break;
667 case LANG_ARMENIAN: l = "hy"; sl = "AM"; break;
668 case LANG_ASSAMESE: l = "as"; sl = "IN"; break;
673 /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
674 case SUBLANG_AZERI_LATIN: sl = "AZ@latin"; break;
675 case SUBLANG_AZERI_CYRILLIC: sl = "AZ@cyrillic"; break;
679 l = "eu"; /* sl could be "ES" or "FR". */
681 case LANG_BELARUSIAN: l = "be"; sl = "BY"; break;
686 case SUBLANG_BENGALI_INDIA: sl = "IN"; break;
687 case SUBLANG_BENGALI_BANGLADESH: sl = "BD"; break;
690 case LANG_BULGARIAN: l = "bg"; sl = "BG"; break;
691 case LANG_BURMESE: l = "my"; sl = "MM"; break;
692 case LANG_CAMBODIAN: l = "km"; sl = "KH"; break;
693 case LANG_CATALAN: l = "ca"; sl = "ES"; break;
698 case SUBLANG_CHINESE_TRADITIONAL: sl = "TW"; break;
699 case SUBLANG_CHINESE_SIMPLIFIED: sl = "CN"; break;
700 case SUBLANG_CHINESE_HONGKONG: sl = "HK"; break;
701 case SUBLANG_CHINESE_SINGAPORE: sl = "SG"; break;
702 case SUBLANG_CHINESE_MACAU: sl = "MO"; break;
705 case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN */
708 /* FIXME: How to distinguish Croatian and Latin Serbian locales? */
709 case SUBLANG_SERBIAN_LATIN: l = "sr"; sl = "@Latn"; break;
710 case SUBLANG_SERBIAN_CYRILLIC: l = "sr"; break;
711 default: l = "hr"; sl = "HR";
714 case LANG_CZECH: l = "cs"; sl = "CZ"; break;
715 case LANG_DANISH: l = "da"; sl = "DK"; break;
716 case LANG_DIVEHI: l = "div"; sl = "MV"; break;
721 case SUBLANG_DUTCH: sl = "NL"; break;
722 case SUBLANG_DUTCH_BELGIAN: sl = "BE"; break;
729 case SUBLANG_ENGLISH_US: sl = "US"; break;
730 case SUBLANG_ENGLISH_UK: sl = "GB"; break;
731 case SUBLANG_ENGLISH_AUS: sl = "AU"; break;
732 case SUBLANG_ENGLISH_CAN: sl = "CA"; break;
733 case SUBLANG_ENGLISH_NZ: sl = "NZ"; break;
734 case SUBLANG_ENGLISH_EIRE: sl = "IE"; break;
735 case SUBLANG_ENGLISH_SOUTH_AFRICA: sl = "ZA"; break;
736 case SUBLANG_ENGLISH_JAMAICA: sl = "JM"; break;
737 case SUBLANG_ENGLISH_CARIBBEAN: sl = "GD"; break; /* Grenada? */
738 case SUBLANG_ENGLISH_BELIZE: sl = "BZ"; break;
739 case SUBLANG_ENGLISH_TRINIDAD: sl = "TT"; break;
740 case SUBLANG_ENGLISH_ZIMBABWE: sl = "ZW"; break;
741 case SUBLANG_ENGLISH_PHILIPPINES: sl = "PH"; break;
742 case SUBLANG_ENGLISH_INDONESIA: sl = "ID"; break;
743 case SUBLANG_ENGLISH_HONGKONG: sl = "HK"; break;
744 case SUBLANG_ENGLISH_INDIA: sl = "IN"; break;
745 case SUBLANG_ENGLISH_MALAYSIA: sl = "MY"; break;
746 case SUBLANG_ENGLISH_SINGAPORE: sl = "SG"; break;
749 case LANG_ESTONIAN: l = "et"; sl = "EE"; break;
750 case LANG_FAEROESE: l = "fo"; sl = "FO"; break;
751 case LANG_FARSI: l = "fa"; sl = "IR"; break;
752 case LANG_FINNISH: l = "fi"; sl = "FI"; break;
757 case SUBLANG_FRENCH: sl = "FR"; break;
758 case SUBLANG_FRENCH_BELGIAN: sl = "BE"; break;
759 case SUBLANG_FRENCH_CANADIAN: sl = "CA"; break;
760 case SUBLANG_FRENCH_SWISS: sl = "CH"; break;
761 case SUBLANG_FRENCH_LUXEMBOURG: sl = "LU"; break;
762 case SUBLANG_FRENCH_MONACO: sl = "MC"; break;
763 case SUBLANG_FRENCH_WESTINDIES: break;
764 case SUBLANG_FRENCH_REUNION: sl = "RE"; break;
765 case SUBLANG_FRENCH_CONGO: sl = "CG"; break;
766 case SUBLANG_FRENCH_SENEGAL: sl = "SN"; break;
767 case SUBLANG_FRENCH_CAMEROON: sl = "CM"; break;
768 case SUBLANG_FRENCH_COTEDIVOIRE: sl = "CI"; break;
769 case SUBLANG_FRENCH_MALI: sl = "ML"; break;
770 case SUBLANG_FRENCH_MOROCCO: sl = "MA"; break;
771 case SUBLANG_FRENCH_HAITI: sl = "HT"; break;
774 case LANG_FRISIAN: l = "fy"; sl ="NL"; break;
775 case LANG_FULFULDE: l = "ful"; sl = "NG"; break;
779 case 0x01: /* SCOTTISH */ l = "gd"; sl = "GB"; break;
780 case 0x02: /* IRISH */ l = "ga"; sl = "IE"; break;
783 case LANG_GALICIAN: l = "gl"; sl = "ES"; break;
784 case LANG_GEORGIAN: l = "ka"; sl = "GE"; break;
789 case SUBLANG_GERMAN: sl = "DE"; break;
790 case SUBLANG_GERMAN_SWISS: sl = "CH"; break;
791 case SUBLANG_GERMAN_AUSTRIAN: sl = "AT"; break;
792 case SUBLANG_GERMAN_LUXEMBOURG: sl = "LU"; break;
793 case SUBLANG_GERMAN_LIECHTENSTEIN: sl = "LI"; break;
796 case LANG_GREEK: l = "el"; sl = "GR"; break;
797 case LANG_GUARANI: l = "gn"; sl = "PY"; break;
798 case LANG_GUJARATI: l = "gu"; sl = "IN"; break;
799 case LANG_HAUSA: l = "ha"; sl = "NG"; break;
801 /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
802 * or Hawaii Creole English ("cpe_US", 600000 speakers)?
807 case LANG_HEBREW: l = "he"; sl = "IL"; break;
808 case LANG_HINDI: l = "hi"; sl = "IN"; break;
809 case LANG_HUNGARIAN: l = "hu"; sl = "HU"; break;
810 case LANG_IBIBIO: l = "nic"; sl = "NG"; break;
811 case LANG_ICELANDIC: l = "is"; sl = "IS"; break;
812 case LANG_IGBO: l = "ibo"; sl = "NG"; break;
813 case LANG_INDONESIAN: l = "id"; sl = "ID"; break;
814 case LANG_INUKTITUT: l = "iu"; sl = "CA"; break;
819 case SUBLANG_ITALIAN: sl = "IT"; break;
820 case SUBLANG_ITALIAN_SWISS: sl = "CH"; break;
823 case LANG_JAPANESE: l = "ja"; sl = "JP"; break;
824 case LANG_KANNADA: l = "kn"; sl = "IN"; break;
825 case LANG_KANURI: l = "kau"; sl = "NG"; break;
830 case SUBLANG_DEFAULT: sl = "PK"; break;
831 case SUBLANG_KASHMIRI_INDIA: sl = "IN"; break;
834 case LANG_KAZAK: l = "kk"; sl = "KZ"; break;
836 /* FIXME: Adjust this when such locales appear on Unix. */
840 case LANG_KOREAN: l = "ko"; sl = "KR"; break;
841 case LANG_KYRGYZ: l = "ky"; sl = "KG"; break;
842 case LANG_LAO: l = "lo"; sl = "LA"; break;
843 case LANG_LATIN: l = "la"; sl = "VA"; break;
844 case LANG_LATVIAN: l = "lv"; sl = "LV"; break;
845 case LANG_LITHUANIAN: l = "lt"; sl = "LT"; break;
846 case LANG_MACEDONIAN: l = "mk"; sl = "MK"; break;
851 case SUBLANG_MALAY_MALAYSIA: sl = "MY"; break;
852 case SUBLANG_MALAY_BRUNEI_DARUSSALAM: sl = "BN"; break;
855 case LANG_MALAYALAM: l = "ml"; sl = "IN"; break;
857 /* FIXME: Adjust this when such locales appear on Unix. */
861 case LANG_MARATHI: l = "mr"; sl = "IN"; break;
863 /* Ambiguous: could be "mn_CN" or "mn_MN". */
870 case SUBLANG_DEFAULT: sl = "NP"; break;
871 case SUBLANG_NEPALI_INDIA: sl = "IN"; break;
878 case SUBLANG_NORWEGIAN_BOKMAL: sl = "NO"; break;
879 case SUBLANG_NORWEGIAN_NYNORSK: l = "nn"; sl = "NO"; break;
882 case LANG_ORIYA: l = "or"; sl = "IN"; break;
883 case LANG_OROMO: l = "om"; sl = "ET"; break;
884 case LANG_PAPIAMENTU: l = "pap"; sl = "AN"; break;
886 /* Ambiguous: could be "ps_PK" or "ps_AF". */
889 case LANG_POLISH: l = "pl"; sl = "PL"; break;
890 case LANG_PORTUGUESE:
894 case SUBLANG_PORTUGUESE: sl = "PT"; break;
895 case SUBLANG_PORTUGUESE_BRAZILIAN: sl = "BR"; break;
902 case SUBLANG_PUNJABI_INDIA: sl = "IN"; break; /* Gurmukhi script */
903 case SUBLANG_PUNJABI_PAKISTAN: sl = "PK"; break; /* Arabic script */
906 case LANG_RHAETO_ROMANCE: l = "rm"; sl = "CH"; break;
911 case SUBLANG_ROMANIAN_ROMANIA: sl = "RO"; break;
912 case SUBLANG_ROMANIAN_MOLDOVA: sl = "MD"; break;
916 l = "ru";/* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
918 case LANG_SAAMI: /* actually Northern Sami */ l = "se"; sl = "NO"; break;
919 case LANG_SANSKRIT: l = "sa"; sl = "IN"; break;
920 case LANG_SINDHI: l = "sd";
923 case SUBLANG_SINDHI_INDIA: sl = "IN"; break;
924 case SUBLANG_SINDHI_PAKISTAN: sl = "PK"; break;
927 case LANG_SINHALESE: l = "si"; sl = "LK"; break;
928 case LANG_SLOVAK: l = "sk"; sl = "SK"; break;
929 case LANG_SLOVENIAN: l = "sl"; sl = "SI"; break;
930 case LANG_SOMALI: l = "so"; sl = "SO"; break;
932 /* FIXME: Adjust this when such locales appear on Unix. */
940 case SUBLANG_SPANISH: sl = "ES"; break;
941 case SUBLANG_SPANISH_MEXICAN: sl = "MX"; break;
942 case SUBLANG_SPANISH_MODERN:
943 sl = "ES@modern"; break; /* not seen on Unix */
944 case SUBLANG_SPANISH_GUATEMALA: sl = "GT"; break;
945 case SUBLANG_SPANISH_COSTA_RICA: sl = "CR"; break;
946 case SUBLANG_SPANISH_PANAMA: sl = "PA"; break;
947 case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: sl = "DO"; break;
948 case SUBLANG_SPANISH_VENEZUELA: sl = "VE"; break;
949 case SUBLANG_SPANISH_COLOMBIA: sl = "CO"; break;
950 case SUBLANG_SPANISH_PERU: sl = "PE"; break;
951 case SUBLANG_SPANISH_ARGENTINA: sl = "AR"; break;
952 case SUBLANG_SPANISH_ECUADOR: sl = "EC"; break;
953 case SUBLANG_SPANISH_CHILE: sl = "CL"; break;
954 case SUBLANG_SPANISH_URUGUAY: sl = "UY"; break;
955 case SUBLANG_SPANISH_PARAGUAY: sl = "PY"; break;
956 case SUBLANG_SPANISH_BOLIVIA: sl = "BO"; break;
957 case SUBLANG_SPANISH_EL_SALVADOR: sl = "SV"; break;
958 case SUBLANG_SPANISH_HONDURAS: sl = "HN"; break;
959 case SUBLANG_SPANISH_NICARAGUA: sl = "NI"; break;
960 case SUBLANG_SPANISH_PUERTO_RICO: sl = "PR"; break;
963 case LANG_SUTU: l = "bnt"; sl = "TZ"; break; /* or "st_LS" or "nso_ZA"? */
964 case LANG_SWAHILI: l = "sw"; sl = "KE"; break;
969 case SUBLANG_DEFAULT: sl = "SE"; break;
970 case SUBLANG_SWEDISH_FINLAND: sl = "FI"; break;
973 case LANG_SYRIAC: l = "syr"; sl = "TR"; break; /* An extinct language. */
974 case LANG_TAGALOG: l = "tl"; sl = "PH"; break;
975 case LANG_TAJIK: l = "tg"; sl = "TJ"; break;
977 l = "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
979 case LANG_TATAR: l = "tt"; sl = "RU"; break;
980 case LANG_TELUGU: l = "te"; sl = "IN"; break;
981 case LANG_THAI: l = "th"; sl = "TH"; break;
982 case LANG_TIBETAN: l = "bo"; sl = "CN"; break;
987 case SUBLANG_TIGRINYA_ETHIOPIA: sl = "ET"; break;
988 case SUBLANG_TIGRINYA_ERITREA: sl = "ER"; break;
991 case LANG_TSONGA: l = "ts"; sl = "ZA"; break;
992 case LANG_TSWANA: l = "tn"; sl = "BW"; break;
993 case LANG_TURKISH: l = "tr"; sl = "TR"; break;
994 case LANG_TURKMEN: l = "tk"; sl = "TM"; break;
995 case LANG_UKRAINIAN: l = "uk"; sl = "UA"; break;
1000 case SUBLANG_URDU_PAKISTAN: sl = "PK"; break;
1001 case SUBLANG_URDU_INDIA: sl = "IN"; break;
1008 case SUBLANG_UZBEK_LATIN: sl = "UZ"; break;
1009 case SUBLANG_UZBEK_CYRILLIC: sl = "UZ@cyrillic"; break;
1013 /* FIXME: It's not clear whether Venda has the ISO 639-2 two-letter code
1015 http://www.loc.gov/standards/iso639-2/englangn.html has it, but
1016 http://lcweb.loc.gov/standards/iso639-2/codechanges.html doesn't, */
1017 l = "ven"; /* or "ve"? */
1020 case LANG_VIETNAMESE: l = "vi"; sl = "VN"; break;
1021 case LANG_WELSH: l = "cy"; sl = "GB"; break;
1022 case LANG_XHOSA: l = "xh"; sl = "ZA"; break;
1023 case LANG_YI: l = "sit"; sl = "CN"; break;
1024 case LANG_YIDDISH: l = "yi"; sl = "IL"; break;
1025 case LANG_YORUBA: l = "yo"; sl = "NG"; break;
1026 case LANG_ZULU: l = "zu"; sl = "ZA"; break;
1036 return g_strdup (bfr);
1040 * g_win32_error_message:
1041 * @error: error code.
1043 * Translate a Win32 error code (as returned by GetLastError()) into
1044 * the corresponding message. The message is either language neutral,
1045 * or in the thread's language, or the user's language, the system's
1046 * language, or US English (see docs for FormatMessage()). The
1047 * returned string is in UTF-8. It should be deallocated with
1050 * Returns: newly-allocated error message
1053 g_win32_error_message (gint error)
1059 FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
1060 |FORMAT_MESSAGE_IGNORE_INSERTS
1061 |FORMAT_MESSAGE_FROM_SYSTEM,
1063 (LPTSTR) &msg, 0, NULL);
1066 nbytes = strlen (msg);
1068 if (nbytes > 2 && msg[nbytes-1] == '\n' && msg[nbytes-2] == '\r')
1069 msg[nbytes-2] = '\0';
1071 retval = g_locale_to_utf8 (msg, -1, NULL, NULL, NULL);
1076 retval = g_strdup ("");
1082 get_package_directory_from_module (gchar *module_name)
1084 static GHashTable *module_dirs = NULL;
1085 G_LOCK_DEFINE_STATIC (module_dirs);
1086 HMODULE hmodule = NULL;
1091 G_LOCK (module_dirs);
1093 if (module_dirs == NULL)
1094 module_dirs = g_hash_table_new (g_str_hash, g_str_equal);
1096 result = g_hash_table_lookup (module_dirs, module_name ? module_name : "");
1100 G_UNLOCK (module_dirs);
1101 return g_strdup (result);
1106 hmodule = GetModuleHandle (module_name);
1111 fn = g_malloc (MAX_PATH);
1112 if (!GetModuleFileName (hmodule, fn, MAX_PATH))
1114 G_UNLOCK (module_dirs);
1119 if ((p = strrchr (fn, G_DIR_SEPARATOR)) != NULL)
1122 p = strrchr (fn, G_DIR_SEPARATOR);
1123 if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0 ||
1124 g_ascii_strcasecmp (p + 1, "lib") == 0))
1127 #ifdef G_WITH_CYGWIN
1128 /* In Cygwin we need to have POSIX paths */
1130 gchar tmp[MAX_PATH];
1132 cygwin_conv_to_posix_path(fn, tmp);
1138 g_hash_table_insert (module_dirs, module_name ? module_name : "", fn);
1140 G_UNLOCK (module_dirs);
1142 return g_strdup (fn);
1146 * g_win32_get_package_installation_directory:
1147 * @package: An identifier for a software package, or %NULL
1148 * @dll_name: The name of a DLL that a package provides, or %NULL.
1150 * Try to determine the installation directory for a software package.
1151 * Typically used by GNU software packages.
1153 * @package should be a short identifier for the package. Typically it
1154 * is the same identifier as used for
1155 * <literal>GETTEXT_PACKAGE</literal> in software configured according
1156 * to GNU standards. The function first looks in the Windows Registry
1157 * for the value <literal>#InstallationDirectory</literal> in the key
1158 * <literal>#HKLM\Software\@package</literal>, and if that value
1159 * exists and is a string, returns that.
1161 * If @package is %NULL, or the above value isn't found in the
1162 * Registry, but @dll_name is non-%NULL, it should name a DLL loaded
1163 * into the current process. Typically that would be the name of the
1164 * DLL calling this function, looking for its installation
1165 * directory. The function then asks Windows what directory that DLL
1166 * was loaded from. If that directory's last component is "bin" or
1167 * "lib", the parent directory is returned, otherwise the directory
1168 * itself. If that DLL isn't loaded, the function proceeds as if
1169 * @dll_name was %NULL.
1171 * If both @package and @dll_name are %NULL, the directory from where
1172 * the main executable of the process was loaded is uses instead in
1173 * the same way as above.
1175 * Returns: a string containing the installation directory for @package.
1176 * The return value should be freed with g_free() when not needed any longer.
1180 g_win32_get_package_installation_directory (gchar *package,
1183 static GHashTable *package_dirs = NULL;
1184 G_LOCK_DEFINE_STATIC (package_dirs);
1185 gchar *result = NULL;
1187 HKEY reg_key = NULL;
1191 if (package != NULL)
1193 G_LOCK (package_dirs);
1195 if (package_dirs == NULL)
1196 package_dirs = g_hash_table_new (g_str_hash, g_str_equal);
1198 result = g_hash_table_lookup (package_dirs, package);
1200 if (result && result[0])
1202 G_UNLOCK (package_dirs);
1203 return g_strdup (result);
1206 key = g_strconcat ("Software\\", package, NULL);
1209 if ((RegOpenKeyEx (HKEY_CURRENT_USER, key, 0,
1210 KEY_QUERY_VALUE, ®_key) == ERROR_SUCCESS
1211 && RegQueryValueEx (reg_key, "InstallationDirectory", 0,
1212 &type, NULL, &nbytes) == ERROR_SUCCESS)
1214 ((RegOpenKeyEx (HKEY_LOCAL_MACHINE, key, 0,
1215 KEY_QUERY_VALUE, ®_key) == ERROR_SUCCESS
1216 && RegQueryValueEx (reg_key, "InstallationDirectory", 0,
1217 &type, NULL, &nbytes) == ERROR_SUCCESS)
1220 result = g_malloc (nbytes + 1);
1221 RegQueryValueEx (reg_key, "InstallationDirectory", 0,
1222 &type, result, &nbytes);
1223 result[nbytes] = '\0';
1226 if (reg_key != NULL)
1227 RegCloseKey (reg_key);
1233 g_hash_table_insert (package_dirs, package, result);
1234 G_UNLOCK (package_dirs);
1235 return g_strdup (result);
1237 G_UNLOCK (package_dirs);
1240 if (dll_name != NULL)
1241 result = get_package_directory_from_module (dll_name);
1244 result = get_package_directory_from_module (NULL);
1250 * g_win32_get_package_installation_subdirectory:
1251 * @package: An identifier for a software package, or %NULL.
1252 * @dll_name: The name of a DLL that a package provides, or %NULL.
1253 * @subdir: A subdirectory of the package installation directory.
1255 * Returns a newly-allocated string containing the path of the
1256 * subdirectory @subdir in the return value from calling
1257 * g_win32_get_package_installation_directory() with the @package and
1258 * @dll_name parameters.
1260 * Returns: a string containing the complete path to @subdir inside the
1261 * installation directory of @package. The return value should be freed with
1262 * g_free() when no longer needed.
1266 g_win32_get_package_installation_subdirectory (gchar *package,
1273 prefix = g_win32_get_package_installation_directory (package, dll_name);
1275 dirname = g_build_filename (prefix, subdir, NULL);
1281 static guint windows_version;
1284 g_win32_windows_version_init (void)
1286 static gboolean beenhere = FALSE;
1291 if (getenv ("G_WIN32_PRETEND_WIN9X"))
1292 windows_version = 0x80000004;
1294 windows_version = GetVersion ();
1299 _g_win32_thread_init (void)
1301 g_win32_windows_version_init ();
1305 g_win32_get_windows_version (void)
1307 g_win32_windows_version_init ();
1309 return windows_version;