]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/win32unix/rename.c
update
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / win32unix / rename.c
1 /***********************************************************************/
2 /*                                                                     */
3 /*                           Objective Caml                            */
4 /*                                                                     */
5 /*  Contributed by Tracy Camp, PolyServe Inc., <campt@polyserve.com>   */
6 /*                                                                     */
7 /*  Copyright 2002 Institut National de Recherche en Informatique et   */
8 /*  en Automatique.  All rights reserved.  This file is distributed    */
9 /*  under the terms of the GNU Library General Public License, with    */
10 /*  the special exception on linking described in file ../../LICENSE.  */
11 /*                                                                     */
12 /***********************************************************************/
13
14 /* $Id: rename.c 6553 2004-07-13 12:25:21Z xleroy $ */
15
16 #include <stdio.h>
17 #include <mlvalues.h>
18 #include "unixsupport.h"
19
20 CAMLprim value unix_rename(value path1, value path2)
21 {
22   static int supports_MoveFileEx = -1; /* don't know yet */
23   BOOL ok;
24
25   if (supports_MoveFileEx < 0) {
26     OSVERSIONINFO VersionInfo;
27     VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
28     supports_MoveFileEx =
29       (GetVersionEx(&VersionInfo) != 0)
30       && (VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
31   }
32   if (supports_MoveFileEx > 0)
33     ok = MoveFileEx(String_val(path1), String_val(path2),
34                     MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH |
35                     MOVEFILE_COPY_ALLOWED);
36   else
37     ok = MoveFile(String_val(path1), String_val(path2));
38   if (! ok) {
39     win32_maperr(GetLastError());
40     uerror("rename", path1);
41   }     
42   return Val_unit;
43 }