1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 1998-2004 Tor Lillqvist
4  *
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.
9  *
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.
14  *
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.
19  */
20 
21 /*
22  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
26  */
27 
28 #include "config.h"
29 
30 #include <stdlib.h>
31 #include <string.h>
32 #include <locale.h>
33 
34 #include "gdkpixmap.h"
35 #include "gdkinternals.h"
36 #include "gdki18n.h"
37 #include "gdkwin32.h"
38 
39 gchar*
gdk_set_locale(void)40 gdk_set_locale (void)
41 {
42   if (!setlocale (LC_ALL, ""))
43     g_warning ("locale not supported by C library");
44 
45   return g_win32_getlocale ();
46 }
47 
48 gchar *
gdk_wcstombs(const GdkWChar * src)49 gdk_wcstombs (const GdkWChar *src)
50 {
51   const gchar *charset;
52 
53   g_get_charset (&charset);
54   return g_convert ((char *) src, -1, charset, "UCS-4LE", NULL, NULL, NULL);
55 }
56 
57 gint
gdk_mbstowcs(GdkWChar * dest,const gchar * src,gint dest_max)58 gdk_mbstowcs (GdkWChar    *dest,
59 	      const gchar *src,
60 	      gint         dest_max)
61 {
62   gint retval;
63   gsize nwritten;
64   gint n_ucs4;
65   gunichar *ucs4;
66   const gchar *charset;
67 
68   g_get_charset (&charset);
69   ucs4 = (gunichar *) g_convert (src, -1, "UCS-4LE", charset, NULL, &nwritten, NULL);
70   n_ucs4 = nwritten * sizeof (GdkWChar);
71 
72   retval = MIN (dest_max, n_ucs4);
73   memmove (dest, ucs4, retval * sizeof (GdkWChar));
74   g_free (ucs4);
75 
76   return retval;
77 }
78