Fix some glib docs warnings
[platform/upstream/glib.git] / glib / gstdio.c
1 /* gstdio.c - wrappers for C library functions
2  *
3  * Copyright 2004 Tor Lillqvist
4  *
5  * GLib is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * GLib 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 GLib; see the file COPYING.LIB.  If not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22
23 #define G_STDIO_NO_WRAP_ON_UNIX
24
25 #include "glib.h"
26
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34
35 #ifdef G_OS_WIN32
36 #include <windows.h>
37 #include <errno.h>
38 #include <wchar.h>
39 #include <direct.h>
40 #include <io.h>
41 #include <sys/utime.h>
42 #else
43 #include <utime.h>
44 #endif
45
46 #include "gstdio.h"
47
48
49 #if !defined (G_OS_UNIX) && !defined (G_OS_WIN32) && !defined (G_OS_BEOS)
50 #error Please port this to your operating system
51 #endif
52
53 #if defined (_MSC_VER) && !defined(_WIN64)
54 #undef _wstat
55 #define _wstat _wstat32
56 #endif
57
58 /**
59  * g_access:
60  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
61  * @mode: as in access()
62  *
63  * A wrapper for the POSIX access() function. This function is used to
64  * test a pathname for one or several of read, write or execute
65  * permissions, or just existence.
66  *
67  * On Windows, the file protection mechanism is not at all POSIX-like,
68  * and the underlying function in the C library only checks the
69  * FAT-style READONLY attribute, and does not look at the ACL of a
70  * file at all. This function is this in practise almost useless on
71  * Windows. Software that needs to handle file permissions on Windows
72  * more exactly should use the Win32 API.
73  *
74  * See your C library manual for more details about access().
75  *
76  * Returns: zero if the pathname refers to an existing file system
77  * object that has all the tested permissions, or -1 otherwise or on
78  * error.
79  * 
80  * Since: 2.8
81  */
82 int
83 g_access (const gchar *filename,
84           int          mode)
85 {
86 #ifdef G_OS_WIN32
87   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
88   int retval;
89   int save_errno;
90     
91   if (wfilename == NULL)
92     {
93       errno = EINVAL;
94       return -1;
95     }
96
97 #ifndef X_OK
98 #define X_OK 1
99 #endif
100
101   retval = _waccess (wfilename, mode & ~X_OK);
102   save_errno = errno;
103
104   g_free (wfilename);
105
106   errno = save_errno;
107   return retval;
108 #else
109   return access (filename, mode);
110 #endif
111 }
112
113 /**
114  * g_chmod:
115  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
116  * @mode: as in chmod()
117  *
118  * A wrapper for the POSIX chmod() function. The chmod() function is
119  * used to set the permissions of a file system object.
120  * 
121  * On Windows the file protection mechanism is not at all POSIX-like,
122  * and the underlying chmod() function in the C library just sets or
123  * clears the FAT-style READONLY attribute. It does not touch any
124  * ACL. Software that needs to manage file permissions on Windows
125  * exactly should use the Win32 API.
126  *
127  * See your C library manual for more details about chmod().
128  *
129  * Returns: zero if the operation succeeded, -1 on error.
130  * 
131  * Since: 2.8
132  */
133 int
134 g_chmod (const gchar *filename,
135          int          mode)
136 {
137 #ifdef G_OS_WIN32
138   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
139   int retval;
140   int save_errno;
141     
142   if (wfilename == NULL)
143     {
144       errno = EINVAL;
145       return -1;
146     }
147
148   retval = _wchmod (wfilename, mode);
149   save_errno = errno;
150
151   g_free (wfilename);
152
153   errno = save_errno;
154   return retval;
155 #else
156   return chmod (filename, mode);
157 #endif
158 }
159 /**
160  * g_open:
161  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
162  * @flags: as in open()
163  * @mode: as in open()
164  *
165  * A wrapper for the POSIX open() function. The open() function is
166  * used to convert a pathname into a file descriptor.
167  *
168  * On POSIX systems file descriptors are implemented by the operating
169  * system. On Windows, it's the C library that implements open() and
170  * file descriptors. The actual Win32 API for opening files is quite
171  * different, see MSDN documentation for CreateFile(). The Win32 API
172  * uses file handles, which are more randomish integers, not small
173  * integers like file descriptors.
174  *
175  * Because file descriptors are specific to the C library on Windows,
176  * the file descriptor returned by this function makes sense only to
177  * functions in the same C library. Thus if the GLib-using code uses a
178  * different C library than GLib does, the file descriptor returned by
179  * this function cannot be passed to C library functions like write()
180  * or read().
181  *
182  * See your C library manual for more details about open().
183  *
184  * Returns: a new file descriptor, or -1 if an error occurred. The
185  * return value can be used exactly like the return value from open().
186  * 
187  * Since: 2.6
188  */
189 int
190 g_open (const gchar *filename,
191         int          flags,
192         int          mode)
193 {
194 #ifdef G_OS_WIN32
195   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
196   int retval;
197   int save_errno;
198     
199   if (wfilename == NULL)
200     {
201       errno = EINVAL;
202       return -1;
203     }
204
205   retval = _wopen (wfilename, flags, mode);
206   save_errno = errno;
207
208   g_free (wfilename);
209
210   errno = save_errno;
211   return retval;
212 #else
213   return open (filename, flags, mode);
214 #endif
215 }
216
217 /**
218  * g_creat:
219  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
220  * @mode: as in creat()
221  *
222  * A wrapper for the POSIX creat() function. The creat() function is
223  * used to convert a pathname into a file descriptor, creating a file
224  * if necessary.
225
226  * On POSIX systems file descriptors are implemented by the operating
227  * system. On Windows, it's the C library that implements creat() and
228  * file descriptors. The actual Windows API for opening files is
229  * different, see MSDN documentation for CreateFile(). The Win32 API
230  * uses file handles, which are more randomish integers, not small
231  * integers like file descriptors.
232  *
233  * Because file descriptors are specific to the C library on Windows,
234  * the file descriptor returned by this function makes sense only to
235  * functions in the same C library. Thus if the GLib-using code uses a
236  * different C library than GLib does, the file descriptor returned by
237  * this function cannot be passed to C library functions like write()
238  * or read().
239  *
240  * See your C library manual for more details about creat().
241  *
242  * Returns: a new file descriptor, or -1 if an error occurred. The
243  * return value can be used exactly like the return value from creat().
244  * 
245  * Since: 2.8
246  */
247 int
248 g_creat (const gchar *filename,
249          int          mode)
250 {
251 #ifdef G_OS_WIN32
252   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
253   int retval;
254   int save_errno;
255     
256   if (wfilename == NULL)
257     {
258       errno = EINVAL;
259       return -1;
260     }
261
262   retval = _wcreat (wfilename, mode);
263   save_errno = errno;
264
265   g_free (wfilename);
266
267   errno = save_errno;
268   return retval;
269 #else
270   return creat (filename, mode);
271 #endif
272 }
273
274 /**
275  * g_rename:
276  * @oldfilename: a pathname in the GLib file name encoding (UTF-8 on Windows)
277  * @newfilename: a pathname in the GLib file name encoding
278  *
279  * A wrapper for the POSIX rename() function. The rename() function 
280  * renames a file, moving it between directories if required.
281  * 
282  * See your C library manual for more details about how rename() works
283  * on your system. It is not possible in general on Windows to rename
284  * a file that is open to some process.
285  *
286  * Returns: 0 if the renaming succeeded, -1 if an error occurred
287  * 
288  * Since: 2.6
289  */
290 int
291 g_rename (const gchar *oldfilename,
292           const gchar *newfilename)
293 {
294 #ifdef G_OS_WIN32
295   wchar_t *woldfilename = g_utf8_to_utf16 (oldfilename, -1, NULL, NULL, NULL);
296   wchar_t *wnewfilename;
297   int retval;
298   int save_errno = 0;
299
300   if (woldfilename == NULL)
301     {
302       errno = EINVAL;
303       return -1;
304     }
305
306   wnewfilename = g_utf8_to_utf16 (newfilename, -1, NULL, NULL, NULL);
307
308   if (wnewfilename == NULL)
309     {
310       g_free (woldfilename);
311       errno = EINVAL;
312       return -1;
313     }
314
315   if (MoveFileExW (woldfilename, wnewfilename, MOVEFILE_REPLACE_EXISTING))
316     retval = 0;
317   else
318     {
319       retval = -1;
320       switch (GetLastError ())
321         {
322 #define CASE(a,b) case ERROR_##a: save_errno = b; break
323           CASE (FILE_NOT_FOUND, ENOENT);
324           CASE (PATH_NOT_FOUND, ENOENT);
325           CASE (ACCESS_DENIED, EACCES);
326           CASE (NOT_SAME_DEVICE, EXDEV);
327           CASE (LOCK_VIOLATION, EACCES);
328           CASE (SHARING_VIOLATION, EACCES);
329           CASE (FILE_EXISTS, EEXIST);
330           CASE (ALREADY_EXISTS, EEXIST);
331 #undef CASE
332         default: save_errno = EIO;
333         }
334     }
335
336   g_free (woldfilename);
337   g_free (wnewfilename);
338     
339   errno = save_errno;
340   return retval;
341 #else
342   return rename (oldfilename, newfilename);
343 #endif
344 }
345
346 /**
347  * g_mkdir: 
348  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
349  * @mode: permissions to use for the newly created directory
350  *
351  * A wrapper for the POSIX mkdir() function. The mkdir() function 
352  * attempts to create a directory with the given name and permissions.
353  * The mode argument is ignored on Windows.
354  * 
355  * See your C library manual for more details about mkdir().
356  *
357  * Returns: 0 if the directory was successfully created, -1 if an error 
358  *    occurred
359  * 
360  * Since: 2.6
361  */
362 int
363 g_mkdir (const gchar *filename,
364          int          mode)
365 {
366 #ifdef G_OS_WIN32
367   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
368   int retval;
369   int save_errno;
370
371   if (wfilename == NULL)
372     {
373       errno = EINVAL;
374       return -1;
375     }
376
377   retval = _wmkdir (wfilename);
378   save_errno = errno;
379
380   g_free (wfilename);
381     
382   errno = save_errno;
383   return retval;
384 #else
385   return mkdir (filename, mode);
386 #endif
387 }
388
389 /**
390  * g_chdir: 
391  * @path: a pathname in the GLib file name encoding (UTF-8 on Windows)
392  *
393  * A wrapper for the POSIX chdir() function. The function changes the
394  * current directory of the process to @path.
395  * 
396  * See your C library manual for more details about chdir().
397  *
398  * Returns: 0 on success, -1 if an error occurred.
399  * 
400  * Since: 2.8
401  */
402 int
403 g_chdir (const gchar *path)
404 {
405 #ifdef G_OS_WIN32
406   wchar_t *wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
407   int retval;
408   int save_errno;
409
410   if (wpath == NULL)
411     {
412       errno = EINVAL;
413       return -1;
414     }
415
416   retval = _wchdir (wpath);
417   save_errno = errno;
418
419   g_free (wpath);
420     
421   errno = save_errno;
422   return retval;
423 #else
424   return chdir (path);
425 #endif
426 }
427
428 /**
429  * GStatBuf:
430  *
431  * A type corresponding to the appropriate struct type for the stat
432  * system call, depending on the platform and/or compiler being used.
433  *
434  * See g_stat() for more information.
435  **/
436 /**
437  * g_stat: 
438  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
439  * @buf: a pointer to a <structname>stat</structname> struct, which
440  *    will be filled with the file information
441  *
442  * A wrapper for the POSIX stat() function. The stat() function
443  * returns information about a file. On Windows the stat() function in
444  * the C library checks only the FAT-style READONLY attribute and does
445  * not look at the ACL at all. Thus on Windows the protection bits in
446  * the st_mode field are a fabrication of little use.
447  * 
448  * On Windows the Microsoft C libraries have several variants of the
449  * <structname>stat</structname> struct and stat() function with names
450  * like "_stat", "_stat32", "_stat32i64" and "_stat64i32". The one
451  * used here is for 32-bit code the one with 32-bit size and time
452  * fields, specifically called "_stat32".
453  *
454  * In Microsoft's compiler, by default "struct stat" means one with
455  * 64-bit time fields while in MinGW "struct stat" is the legacy one
456  * with 32-bit fields. To hopefully clear up this messs, the gstdio.h
457  * header defines a type GStatBuf which is the appropriate struct type
458  * depending on the platform and/or compiler being used. On POSIX it
459  * is just "struct stat", but note that even on POSIX platforms,
460  * "stat" might be a macro.
461  *
462  * See your C library manual for more details about stat().
463  *
464  * Returns: 0 if the information was successfully retrieved, -1 if an error 
465  *    occurred
466  * 
467  * Since: 2.6
468  */
469 int
470 g_stat (const gchar *filename,
471         GStatBuf    *buf)
472 {
473 #ifdef G_OS_WIN32
474   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
475   int retval;
476   int save_errno;
477   int len;
478
479   if (wfilename == NULL)
480     {
481       errno = EINVAL;
482       return -1;
483     }
484
485   len = wcslen (wfilename);
486   while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1]))
487     len--;
488   if (len > 0 &&
489       (!g_path_is_absolute (filename) || len > g_path_skip_root (filename) - filename))
490     wfilename[len] = '\0';
491
492   retval = _wstat (wfilename, buf);
493   save_errno = errno;
494
495   g_free (wfilename);
496
497   errno = save_errno;
498   return retval;
499 #else
500   return stat (filename, buf);
501 #endif
502 }
503
504 /**
505  * g_lstat: 
506  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
507  * @buf: a pointer to a <structname>stat</structname> struct, which
508  *    will be filled with the file information
509  *
510  * A wrapper for the POSIX lstat() function. The lstat() function is
511  * like stat() except that in the case of symbolic links, it returns
512  * information about the symbolic link itself and not the file that it
513  * refers to. If the system does not support symbolic links g_lstat()
514  * is identical to g_stat().
515  * 
516  * See your C library manual for more details about lstat().
517  *
518  * Returns: 0 if the information was successfully retrieved, -1 if an error 
519  *    occurred
520  * 
521  * Since: 2.6
522  */
523 int
524 g_lstat (const gchar *filename,
525          GStatBuf    *buf)
526 {
527 #ifdef HAVE_LSTAT
528   /* This can't be Win32, so don't do the widechar dance. */
529   return lstat (filename, buf);
530 #else
531   return g_stat (filename, buf);
532 #endif
533 }
534
535 /**
536  * g_unlink:
537  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
538  *
539  * A wrapper for the POSIX unlink() function. The unlink() function 
540  * deletes a name from the filesystem. If this was the last link to the 
541  * file and no processes have it opened, the diskspace occupied by the
542  * file is freed.
543  * 
544  * See your C library manual for more details about unlink(). Note
545  * that on Windows, it is in general not possible to delete files that
546  * are open to some process, or mapped into memory.
547  *
548  * Returns: 0 if the name was successfully deleted, -1 if an error 
549  *    occurred
550  * 
551  * Since: 2.6
552  */
553 int
554 g_unlink (const gchar *filename)
555 {
556 #ifdef G_OS_WIN32
557   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
558   int retval;
559   int save_errno;
560
561   if (wfilename == NULL)
562     {
563       errno = EINVAL;
564       return -1;
565     }
566
567   retval = _wunlink (wfilename);
568   save_errno = errno;
569
570   g_free (wfilename);
571
572   errno = save_errno;
573   return retval;
574 #else
575   return unlink (filename);
576 #endif
577 }
578
579 /**
580  * g_remove:
581  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
582  *
583  * A wrapper for the POSIX remove() function. The remove() function
584  * deletes a name from the filesystem.
585  * 
586  * See your C library manual for more details about how remove() works
587  * on your system. On Unix, remove() removes also directories, as it
588  * calls unlink() for files and rmdir() for directories. On Windows,
589  * although remove() in the C library only works for files, this
590  * function tries first remove() and then if that fails rmdir(), and
591  * thus works for both files and directories. Note however, that on
592  * Windows, it is in general not possible to remove a file that is
593  * open to some process, or mapped into memory.
594  *
595  * If this function fails on Windows you can't infer too much from the
596  * errno value. rmdir() is tried regardless of what caused remove() to
597  * fail. Any errno value set by remove() will be overwritten by that
598  * set by rmdir().
599  *
600  * Returns: 0 if the file was successfully removed, -1 if an error 
601  *    occurred
602  * 
603  * Since: 2.6
604  */
605 int
606 g_remove (const gchar *filename)
607 {
608 #ifdef G_OS_WIN32
609   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
610   int retval;
611   int save_errno;
612
613   if (wfilename == NULL)
614     {
615       errno = EINVAL;
616       return -1;
617     }
618
619   retval = _wremove (wfilename);
620   if (retval == -1)
621     retval = _wrmdir (wfilename);
622   save_errno = errno;
623
624   g_free (wfilename);
625
626   errno = save_errno;
627   return retval;
628 #else
629   return remove (filename);
630 #endif
631 }
632
633 /**
634  * g_rmdir:
635  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
636  *
637  * A wrapper for the POSIX rmdir() function. The rmdir() function
638  * deletes a directory from the filesystem.
639  * 
640  * See your C library manual for more details about how rmdir() works
641  * on your system.
642  *
643  * Returns: 0 if the directory was successfully removed, -1 if an error 
644  *    occurred
645  * 
646  * Since: 2.6
647  */
648 int
649 g_rmdir (const gchar *filename)
650 {
651 #ifdef G_OS_WIN32
652   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
653   int retval;
654   int save_errno;
655
656   if (wfilename == NULL)
657     {
658       errno = EINVAL;
659       return -1;
660     }
661   
662   retval = _wrmdir (wfilename);
663   save_errno = errno;
664
665   g_free (wfilename);
666
667   errno = save_errno;
668   return retval;
669 #else
670   return rmdir (filename);
671 #endif
672 }
673
674 /**
675  * g_fopen:
676  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
677  * @mode: a string describing the mode in which the file should be 
678  *   opened
679  *
680  * A wrapper for the stdio fopen() function. The fopen() function
681  * opens a file and associates a new stream with it.
682  * 
683  * Because file descriptors are specific to the C library on Windows,
684  * and a file descriptor is partof the <type>FILE</type> struct, the
685  * <type>FILE</type> pointer returned by this function makes sense
686  * only to functions in the same C library. Thus if the GLib-using
687  * code uses a different C library than GLib does, the
688  * <type>FILE</type> pointer returned by this function cannot be
689  * passed to C library functions like fprintf() or fread().
690  *
691  * See your C library manual for more details about fopen().
692  *
693  * Returns: A <type>FILE</type> pointer if the file was successfully
694  *    opened, or %NULL if an error occurred
695  * 
696  * Since: 2.6
697  */
698 FILE *
699 g_fopen (const gchar *filename,
700          const gchar *mode)
701 {
702 #ifdef G_OS_WIN32
703   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
704   wchar_t *wmode;
705   FILE *retval;
706   int save_errno;
707
708   if (wfilename == NULL)
709     {
710       errno = EINVAL;
711       return NULL;
712     }
713
714   wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
715
716   if (wmode == NULL)
717     {
718       g_free (wfilename);
719       errno = EINVAL;
720       return NULL;
721     }
722
723   retval = _wfopen (wfilename, wmode);
724   save_errno = errno;
725
726   g_free (wfilename);
727   g_free (wmode);
728
729   errno = save_errno;
730   return retval;
731 #else
732   return fopen (filename, mode);
733 #endif
734 }
735
736 /**
737  * g_freopen:
738  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
739  * @mode: a string describing the mode in which the file should be 
740  *   opened
741  * @stream: an existing stream which will be reused, or %NULL
742  *
743  * A wrapper for the POSIX freopen() function. The freopen() function
744  * opens a file and associates it with an existing stream.
745  * 
746  * See your C library manual for more details about freopen().
747  *
748  * Returns: A <type>FILE</type> pointer if the file was successfully
749  *    opened, or %NULL if an error occurred.
750  * 
751  * Since: 2.6
752  */
753 FILE *
754 g_freopen (const gchar *filename,
755            const gchar *mode,
756            FILE        *stream)
757 {
758 #ifdef G_OS_WIN32
759   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
760   wchar_t *wmode;
761   FILE *retval;
762   int save_errno;
763
764   if (wfilename == NULL)
765     {
766       errno = EINVAL;
767       return NULL;
768     }
769   
770   wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
771
772   if (wmode == NULL)
773     {
774       g_free (wfilename);
775       errno = EINVAL;
776       return NULL;
777     }
778   
779   retval = _wfreopen (wfilename, wmode, stream);
780   save_errno = errno;
781
782   g_free (wfilename);
783   g_free (wmode);
784
785   errno = save_errno;
786   return retval;
787 #else
788   return freopen (filename, mode, stream);
789 #endif
790 }
791
792 /**
793  * g_utime:
794  * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
795  * @utb: a pointer to a struct utimbuf.
796  *
797  * A wrapper for the POSIX utime() function. The utime() function
798  * sets the access and modification timestamps of a file.
799  * 
800  * See your C library manual for more details about how utime() works
801  * on your system.
802  *
803  * Returns: 0 if the operation was successful, -1 if an error 
804  *    occurred
805  * 
806  * Since: 2.18
807  */
808 int
809 g_utime (const gchar    *filename,
810          struct utimbuf *utb)
811 {
812 #ifdef G_OS_WIN32
813   wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
814   int retval;
815   int save_errno;
816
817   if (wfilename == NULL)
818     {
819       errno = EINVAL;
820       return -1;
821     }
822   
823   retval = _wutime (wfilename, (struct _utimbuf*) utb);
824   save_errno = errno;
825
826   g_free (wfilename);
827
828   errno = save_errno;
829   return retval;
830 #else
831   return utime (filename, utb);
832 #endif
833 }