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