513af9f39c8257a2c32438293826eb872fc52a0d
[platform/upstream/glib.git] / glib / gutils.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1998  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-1999.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 /* 
28  * MT safe for the unix part, FIXME: make the win32 part MT safe as well.
29  */
30
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34
35 #include "glibconfig.h"
36
37 #ifdef HAVE_UNISTD_H
38 #include <unistd.h>
39 #endif
40 #include <stdarg.h>
41 #include <stdlib.h>
42 #include <stdio.h>
43 #include <string.h>
44 #include <errno.h>
45 #ifdef HAVE_PWD_H
46 #include <pwd.h>
47 #endif
48 #include <sys/types.h>
49 #ifdef HAVE_SYS_PARAM_H
50 #include <sys/param.h>
51 #endif
52
53 #ifdef NATIVE_WIN32
54 #  define STRICT                        /* Strict typing, please */
55 #  include <windows.h>
56 #  include <direct.h>
57 #  include <errno.h>
58 #  include <ctype.h>
59 #  ifdef _MSC_VER
60 #    include <io.h>
61 #  endif /* _MSC_VER */
62 #endif /* NATIVE_WIN32 */
63
64 /* implement Glib's inline functions
65  */
66 #define G_INLINE_FUNC extern
67 #define G_CAN_INLINE 1
68 #include "glib.h"
69
70 #ifdef  MAXPATHLEN
71 #define G_PATH_LENGTH   (MAXPATHLEN + 1)
72 #elif   defined (PATH_MAX)
73 #define G_PATH_LENGTH   (PATH_MAX + 1)
74 #else   /* !MAXPATHLEN */
75 #define G_PATH_LENGTH   (2048 + 1)
76 #endif  /* !MAXPATHLEN && !PATH_MAX */
77
78 const guint glib_major_version = GLIB_MAJOR_VERSION;
79 const guint glib_minor_version = GLIB_MINOR_VERSION;
80 const guint glib_micro_version = GLIB_MICRO_VERSION;
81 const guint glib_interface_age = GLIB_INTERFACE_AGE;
82 const guint glib_binary_age = GLIB_BINARY_AGE;
83
84 #if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY)
85 void 
86 g_memmove (gpointer dest, gconstpointer src, gulong len)
87 {
88   gchar* destptr = dest;
89   const gchar* srcptr = src;
90   if (src + len < dest || dest + len < src)
91     {
92       bcopy (src, dest, len);
93       return;
94     }
95   else if (dest <= src)
96     {
97       while (len--)
98         *(destptr++) = *(srcptr++);
99     }
100   else
101     {
102       destptr += len;
103       srcptr += len;
104       while (len--)
105         *(--destptr) = *(--srcptr);
106     }
107 }
108 #endif /* !HAVE_MEMMOVE && !HAVE_WORKING_BCOPY */
109
110 void
111 g_atexit (GVoidFunc func)
112 {
113   gint result;
114   gchar *error = NULL;
115
116   /* keep this in sync with glib.h */
117
118 #ifdef  G_NATIVE_ATEXIT
119   result = ATEXIT (func);
120   if (result)
121     error = g_strerror (errno);
122 #elif defined (HAVE_ATEXIT)
123 #  ifdef NeXT /* @#%@! NeXTStep */
124   result = !atexit ((void (*)(void)) func);
125   if (result)
126     error = g_strerror (errno);
127 #  else
128   result = atexit ((void (*)(void)) func);
129   if (result)
130     error = g_strerror (errno);
131 #  endif /* NeXT */
132 #elif defined (HAVE_ON_EXIT)
133   result = on_exit ((void (*)(int, void *)) func, NULL);
134   if (result)
135     error = g_strerror (errno);
136 #else
137   result = 0;
138   error = "no implementation";
139 #endif /* G_NATIVE_ATEXIT */
140
141   if (error)
142     g_error ("Could not register atexit() function: %s", error);
143 }
144
145 gint
146 g_snprintf (gchar       *str,
147             gulong       n,
148             gchar const *fmt,
149             ...)
150 {
151 #ifdef  HAVE_VSNPRINTF
152   va_list args;
153   gint retval;
154   
155   va_start (args, fmt);
156   retval = vsnprintf (str, n, fmt, args);
157   va_end (args);
158   
159   return retval;
160 #else   /* !HAVE_VSNPRINTF */
161   gchar *printed;
162   va_list args;
163   
164   va_start (args, fmt);
165   printed = g_strdup_vprintf (fmt, args);
166   va_end (args);
167   
168   strncpy (str, printed, n);
169   str[n-1] = '\0';
170
171   g_free (printed);
172   
173   return strlen (str);
174 #endif  /* !HAVE_VSNPRINTF */
175 }
176
177 gint
178 g_vsnprintf (gchar       *str,
179              gulong       n,
180              gchar const *fmt,
181              va_list      args)
182 {
183 #ifdef  HAVE_VSNPRINTF
184   gint retval;
185   
186   retval = vsnprintf (str, n, fmt, args);
187   
188   return retval;
189 #else   /* !HAVE_VSNPRINTF */
190   gchar *printed;
191   
192   printed = g_strdup_vprintf (fmt, args);
193   strncpy (str, printed, n);
194   str[n-1] = '\0';
195
196   g_free (printed);
197   
198   return strlen (str);
199 #endif /* !HAVE_VSNPRINTF */
200 }
201
202 guint        
203 g_parse_debug_string  (const gchar *string, 
204                        GDebugKey   *keys, 
205                        guint        nkeys)
206 {
207   guint i;
208   guint result = 0;
209   
210   g_return_val_if_fail (string != NULL, 0);
211   
212   if (!g_strcasecmp (string, "all"))
213     {
214       for (i=0; i<nkeys; i++)
215         result |= keys[i].value;
216     }
217   else
218     {
219       gchar *str = g_strdup (string);
220       gchar *p = str;
221       gchar *q;
222       gboolean done = FALSE;
223       
224       while (*p && !done)
225         {
226           q = strchr (p, ':');
227           if (!q)
228             {
229               q = p + strlen(p);
230               done = TRUE;
231             }
232           
233           *q = 0;
234           
235           for (i=0; i<nkeys; i++)
236             if (!g_strcasecmp(keys[i].key, p))
237               result |= keys[i].value;
238           
239           p = q+1;
240         }
241       
242       g_free (str);
243     }
244   
245   return result;
246 }
247
248 gchar*
249 g_basename (const gchar    *file_name)
250 {
251   register gchar *base;
252   
253   g_return_val_if_fail (file_name != NULL, NULL);
254   
255   base = strrchr (file_name, G_DIR_SEPARATOR);
256   if (base)
257     return base + 1;
258
259 #ifdef NATIVE_WIN32
260   if (isalpha (file_name[0]) && file_name[1] == ':')
261     return (gchar*) file_name + 2;
262 #endif /* NATIVE_WIN32 */
263   
264   return (gchar*) file_name;
265 }
266
267 gboolean
268 g_path_is_absolute (const gchar *file_name)
269 {
270   g_return_val_if_fail (file_name != NULL, FALSE);
271   
272   if (file_name[0] == G_DIR_SEPARATOR)
273     return TRUE;
274
275 #ifdef NATIVE_WIN32
276   if (isalpha (file_name[0]) && file_name[1] == ':' && file_name[2] == G_DIR_SEPARATOR)
277     return TRUE;
278 #endif
279
280   return FALSE;
281 }
282
283 gchar*
284 g_path_skip_root (gchar *file_name)
285 {
286   g_return_val_if_fail (file_name != NULL, NULL);
287   
288   if (file_name[0] == G_DIR_SEPARATOR)
289     return file_name + 1;
290
291 #ifdef NATIVE_WIN32
292   if (isalpha (file_name[0]) && file_name[1] == ':' && file_name[2] == G_DIR_SEPARATOR)
293     return file_name + 3;
294 #endif
295
296   return NULL;
297 }
298
299 gchar*
300 g_dirname (const gchar     *file_name)
301 {
302   register gchar *base;
303   register guint len;
304   
305   g_return_val_if_fail (file_name != NULL, NULL);
306   
307   base = strrchr (file_name, G_DIR_SEPARATOR);
308   if (!base)
309     return g_strdup (".");
310   while (base > file_name && *base == G_DIR_SEPARATOR)
311     base--;
312   len = (guint) 1 + base - file_name;
313   
314   base = g_new (gchar, len + 1);
315   g_memmove (base, file_name, len);
316   base[len] = 0;
317   
318   return base;
319 }
320
321 gchar*
322 g_get_current_dir (void)
323 {
324   gchar *buffer;
325   gchar *dir;
326
327   buffer = g_new (gchar, G_PATH_LENGTH);
328   *buffer = 0;
329   
330   /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
331    * and, if that wasn't bad enough, hangs in doing so.
332    */
333 #if     defined (sun) && !defined (__SVR4)
334   dir = getwd (buffer);
335 #else   /* !sun */
336   dir = getcwd (buffer, G_PATH_LENGTH - 1);
337 #endif  /* !sun */
338   
339   if (!dir || !*buffer)
340     {
341       /* hm, should we g_error() out here?
342        * this can happen if e.g. "./" has mode \0000
343        */
344       buffer[0] = G_DIR_SEPARATOR;
345       buffer[1] = 0;
346     }
347
348   dir = g_strdup (buffer);
349   g_free (buffer);
350   
351   return dir;
352 }
353
354 gchar*
355 g_getenv (const gchar *variable)
356 {
357 #ifndef NATIVE_WIN32
358   g_return_val_if_fail (variable != NULL, NULL);
359
360   return getenv (variable);
361 #else
362   gchar *v;
363   guint k;
364   static gchar *p = NULL;
365   static gint l;
366   gchar dummy[2];
367
368   g_return_val_if_fail (variable != NULL, NULL);
369   
370   v = getenv (variable);
371   if (!v)
372     return NULL;
373   
374   /* On Windows NT, it is relatively typical that environment variables
375    * contain references to other environment variables. Handle that by
376    * calling ExpandEnvironmentStrings.
377    */
378
379   /* First check how much space we need */
380   k = ExpandEnvironmentStrings (v, dummy, 2);
381   /* Then allocate that much, and actualy do the expansion */
382   if (p == NULL)
383     {
384       p = g_malloc (k);
385       l = k;
386     }
387   else if (k > l)
388     {
389       p = g_realloc (p, k);
390       l = k;
391     }
392   ExpandEnvironmentStrings (v, p, k);
393   return p;
394 #endif
395 }
396
397
398 G_LOCK_DEFINE_STATIC (g_utils_global);
399
400 static  gchar   *g_tmp_dir = NULL;
401 static  gchar   *g_user_name = NULL;
402 static  gchar   *g_real_name = NULL;
403 static  gchar   *g_home_dir = NULL;
404
405 /* HOLDS: g_utils_global_lock */
406 static void
407 g_get_any_init (void)
408 {
409   if (!g_tmp_dir)
410     {
411       g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
412       if (!g_tmp_dir)
413         g_tmp_dir = g_strdup (g_getenv ("TMP"));
414       if (!g_tmp_dir)
415         g_tmp_dir = g_strdup (g_getenv ("TEMP"));
416       
417 #ifdef P_tmpdir
418       if (!g_tmp_dir)
419         {
420           int k;
421           g_tmp_dir = g_strdup (P_tmpdir);
422           k = strlen (g_tmp_dir);
423           if (g_tmp_dir[k-1] == G_DIR_SEPARATOR)
424             g_tmp_dir[k-1] = '\0';
425         }
426 #endif
427       
428       if (!g_tmp_dir)
429         {
430 #ifndef NATIVE_WIN32
431           g_tmp_dir = g_strdup ("/tmp");
432 #else /* NATIVE_WIN32 */
433           g_tmp_dir = g_strdup ("C:\\");
434 #endif /* NATIVE_WIN32 */
435         }
436       
437       if (!g_home_dir)
438         g_home_dir = g_strdup (g_getenv ("HOME"));
439       
440 #ifdef NATIVE_WIN32
441       if (!g_home_dir)
442         {
443           /* The official way to specify a home directory on NT is
444            * the HOMEDRIVE and HOMEPATH environment variables.
445            *
446            * This is inside #ifdef NATIVE_WIN32 because with the cygwin dll,
447            * HOME should be a POSIX style pathname.
448            */
449           
450           if (getenv ("HOMEDRIVE") != NULL && getenv ("HOMEPATH") != NULL)
451             {
452               gchar *homedrive, *homepath;
453               
454               homedrive = g_strdup (g_getenv ("HOMEDRIVE"));
455               homepath = g_strdup (g_getenv ("HOMEPATH"));
456               
457               g_home_dir = g_strconcat (homedrive, homepath, NULL);
458               g_free (homedrive);
459               g_free (homepath);
460             }
461         }
462 #endif /* !NATIVE_WIN32 */
463       
464 #ifdef HAVE_PWD_H
465       {
466         struct passwd *pw = NULL;
467         gpointer buffer = NULL;
468         
469 #  ifdef HAVE_GETPWUID_R
470         struct passwd pwd;
471 #    ifdef _SC_GETPW_R_SIZE_MAX  
472         /* This reurns the maximum length */
473         guint bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
474 #    else /* _SC_GETPW_R_SIZE_MAX */
475         guint bufsize = 64;
476 #    endif /* _SC_GETPW_R_SIZE_MAX */
477         gint error;
478         
479         do
480           {
481             g_free (buffer);
482             buffer = g_malloc (bufsize);
483             errno = 0;
484             
485 #    ifdef HAVE_GETPWUID_R_POSIX
486             error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
487             error = error < 0 ? errno : error;
488 #    else /* !HAVE_GETPWUID_R_POSIX */
489 #      ifdef _AIX
490             error = getpwuid_r (getuid (), &pwd, buffer, bufsize);
491             pw = error == 0 ? &pwd : NULL;
492 #      else /* !_AIX */
493             pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
494             error = pw ? 0 : errno;
495 #      endif /* !_AIX */            
496 #    endif /* !HAVE_GETPWUID_R_POSIX */
497             
498             if (!pw)
499               {
500                 /* we bail out prematurely if the user id can't be found
501                  * (should be pretty rare case actually), or if the buffer
502                  * should be sufficiently big and lookups are still not
503                  * successfull.
504                  */
505                 if (error == 0 || error == ENOENT)
506                   {
507                     g_warning ("getpwuid_r(): failed due to: " 
508                                "No such user: %lu.", (unsigned long)getuid ());
509                     break;
510                   }
511                 if (bufsize > 32 * 1024)
512                   {
513                     g_warning ("getpwuid_r(): failed due to: %s.",
514                                g_strerror (error));
515                     break;
516                   }
517                 
518                 bufsize *= 2;
519               }
520           }
521         while (!pw);
522 #  endif /* !HAVE_GETPWUID_R */
523         
524         if (!pw)
525           {
526             setpwent ();
527             pw = getpwuid (getuid ());
528             endpwent ();
529           }
530         if (pw)
531           {
532             g_user_name = g_strdup (pw->pw_name);
533 #ifdef HAVE_PW_GECOS
534             g_real_name = g_strdup (pw->pw_gecos);
535 #else
536             g_real_name = g_strdup (g_user_name);
537 #endif
538             if (!g_home_dir)
539               g_home_dir = g_strdup (pw->pw_dir);
540           }
541         g_free (buffer);
542       }
543       
544 #else /* !HAVE_PWD_H */
545       
546 #  ifdef NATIVE_WIN32
547       {
548         guint len = 17;
549         gchar buffer[17];
550         
551         if (GetUserName (buffer, &len))
552           {
553             g_user_name = g_strdup (buffer);
554             g_real_name = g_strdup (buffer);
555           }
556       }
557 #  endif /* NATIVE_WIN32 */
558       
559 #endif /* !HAVE_PWD_H */
560       
561 #ifdef __EMX__
562       /* change '\\' in %HOME% to '/' */
563       g_strdelimit (g_home_dir, "\\",'/');
564 #endif
565       if (!g_user_name)
566         g_user_name = g_strdup ("somebody");
567       if (!g_real_name)
568         g_real_name = g_strdup ("Unknown");
569       else
570         {
571           gchar *p;
572
573           for (p = g_real_name; *p; p++)
574             if (*p == ',')
575               {
576                 *p = 0;
577                 p = g_strdup (g_real_name);
578                 g_free (g_real_name);
579                 g_real_name = p;
580                 break;
581               }
582         }
583     }
584 }
585
586 gchar*
587 g_get_user_name (void)
588 {
589   G_LOCK (g_utils_global);
590   if (!g_tmp_dir)
591     g_get_any_init ();
592   G_UNLOCK (g_utils_global);
593   
594   return g_user_name;
595 }
596
597 gchar*
598 g_get_real_name (void)
599 {
600   G_LOCK (g_utils_global);
601   if (!g_tmp_dir)
602     g_get_any_init ();
603   G_UNLOCK (g_utils_global);
604  
605   return g_real_name;
606 }
607
608 /* Return the home directory of the user. If there is a HOME
609  * environment variable, its value is returned, otherwise use some
610  * system-dependent way of finding it out. If no home directory can be
611  * deduced, return NULL.
612  */
613
614 gchar*
615 g_get_home_dir (void)
616 {
617   G_LOCK (g_utils_global);
618   if (!g_tmp_dir)
619     g_get_any_init ();
620   G_UNLOCK (g_utils_global);
621   
622   return g_home_dir;
623 }
624
625 /* Return a directory to be used to store temporary files. This is the
626  * value of the TMPDIR, TMP or TEMP environment variables (they are
627  * checked in that order). If none of those exist, use P_tmpdir from
628  * stdio.h.  If that isn't defined, return "/tmp" on POSIXly systems,
629  * and C:\ on Windows.
630  */
631
632 gchar*
633 g_get_tmp_dir (void)
634 {
635   G_LOCK (g_utils_global);
636   if (!g_tmp_dir)
637     g_get_any_init ();
638   G_UNLOCK (g_utils_global);
639   
640   return g_tmp_dir;
641 }
642
643 static gchar *g_prgname = NULL;
644
645 gchar*
646 g_get_prgname (void)
647 {
648   gchar* retval;
649
650   G_LOCK (g_utils_global);
651   retval = g_prgname;
652   G_UNLOCK (g_utils_global);
653
654   return retval;
655 }
656
657 void
658 g_set_prgname (const gchar *prgname)
659 {
660   gchar *c;
661     
662   G_LOCK (g_utils_global);
663   c = g_prgname;
664   g_prgname = g_strdup (prgname);
665   g_free (c);
666   G_UNLOCK (g_utils_global);
667 }
668
669 guint
670 g_direct_hash (gconstpointer v)
671 {
672   return GPOINTER_TO_UINT (v);
673 }
674
675 gint
676 g_direct_equal (gconstpointer v1,
677                 gconstpointer v2)
678 {
679   return v1 == v2;
680 }
681
682 gint
683 g_int_equal (gconstpointer v1,
684              gconstpointer v2)
685 {
686   return *((const gint*) v1) == *((const gint*) v2);
687 }
688
689 guint
690 g_int_hash (gconstpointer v)
691 {
692   return *(const gint*) v;
693 }
694
695 #ifdef NATIVE_WIN32
696
697 int
698 gwin_ftruncate (gint  fd,
699                 guint size)
700 {
701   HANDLE hfile;
702   guint curpos;
703
704   g_return_val_if_fail (fd >= 0, -1);
705   
706   hfile = (HANDLE) _get_osfhandle (fd);
707   curpos = SetFilePointer (hfile, 0, NULL, FILE_CURRENT);
708   if (curpos == 0xFFFFFFFF
709       || SetFilePointer (hfile, size, NULL, FILE_BEGIN) == 0xFFFFFFFF
710       || !SetEndOfFile (hfile))
711     {
712       gint error = GetLastError ();
713
714       switch (error)
715         {
716         case ERROR_INVALID_HANDLE:
717           errno = EBADF;
718           break;
719         default:
720           errno = EIO;
721           break;
722         }
723
724       return -1;
725     }
726
727   return 0;
728 }
729
730 DIR*
731 gwin_opendir (const char *dirname)
732 {
733   DIR *result;
734   gchar *mask;
735   guint k;
736
737   g_return_val_if_fail (dirname != NULL, NULL);
738
739   result = g_new0 (DIR, 1);
740   result->find_file_data = g_new0 (WIN32_FIND_DATA, 1);
741   result->dir_name = g_strdup (dirname);
742   
743   k = strlen (result->dir_name);
744   if (k && result->dir_name[k - 1] == '\\')
745     {
746       result->dir_name[k - 1] = '\0';
747       k--;
748     }
749   mask = g_strdup_printf ("%s\\*", result->dir_name);
750
751   result->find_file_handle = (guint) FindFirstFile (mask,
752                                              (LPWIN32_FIND_DATA) result->find_file_data);
753   g_free (mask);
754
755   if (result->find_file_handle == (guint) INVALID_HANDLE_VALUE)
756     {
757       int error = GetLastError ();
758
759       g_free (result->dir_name);
760       g_free (result->find_file_data);
761       g_free (result);
762       switch (error)
763         {
764         default:
765           errno = EIO;
766           return NULL;
767         }
768     }
769   result->just_opened = TRUE;
770
771   return result;
772 }
773
774 struct dirent*
775 gwin_readdir (DIR *dir)
776 {
777   static struct dirent result;
778
779   g_return_val_if_fail (dir != NULL, NULL);
780
781   if (dir->just_opened)
782     dir->just_opened = FALSE;
783   else
784     {
785       if (!FindNextFile ((HANDLE) dir->find_file_handle,
786                          (LPWIN32_FIND_DATA) dir->find_file_data))
787         {
788           int error = GetLastError ();
789
790           switch (error)
791             {
792             case ERROR_NO_MORE_FILES:
793               return NULL;
794             default:
795               errno = EIO;
796               return NULL;
797             }
798         }
799     }
800   strcpy (result.d_name, g_basename (((LPWIN32_FIND_DATA) dir->find_file_data)->cFileName));
801       
802   return &result;
803 }
804
805 void
806 gwin_rewinddir (DIR *dir)
807 {
808   gchar *mask;
809
810   g_return_if_fail (dir != NULL);
811
812   if (!FindClose ((HANDLE) dir->find_file_handle))
813     g_warning ("gwin_rewinddir(): FindClose() failed\n");
814
815   mask = g_strdup_printf ("%s\\*", dir->dir_name);
816   dir->find_file_handle = (guint) FindFirstFile (mask,
817                                           (LPWIN32_FIND_DATA) dir->find_file_data);
818   g_free (mask);
819
820   if (dir->find_file_handle == (guint) INVALID_HANDLE_VALUE)
821     {
822       int error = GetLastError ();
823
824       switch (error)
825         {
826         default:
827           errno = EIO;
828           return;
829         }
830     }
831   dir->just_opened = TRUE;
832 }  
833
834 gint
835 gwin_closedir (DIR *dir)
836 {
837   g_return_val_if_fail (dir != NULL, -1);
838
839   if (!FindClose ((HANDLE) dir->find_file_handle))
840     {
841       int error = GetLastError ();
842
843       switch (error)
844         {
845         default:
846           errno = EIO; return -1;
847         }
848     }
849
850   g_free (dir->dir_name);
851   g_free (dir->find_file_data);
852   g_free (dir);
853
854   return 0;
855 }
856
857 #endif /* NATIVE_WIN32 */