1 /**************************************************************************/
2 /* */
3 /* OCaml */
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. */
9 /* */
10 /* All rights reserved. This file is distributed under the terms of */
11 /* the GNU Lesser General Public License version 2.1, with the */
12 /* special exception on linking described in the file LICENSE. */
13 /* */
14 /**************************************************************************/
15
16 #include <stdio.h>
17 #include <caml/mlvalues.h>
18 #include "unixsupport.h"
19
unix_rename(value path1,value path2)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 caml_unix_check_path(path1, "rename");
26 caml_unix_check_path(path2, "rename");
27 if (supports_MoveFileEx < 0) {
28 OSVERSIONINFO VersionInfo;
29 VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
30 supports_MoveFileEx =
31 (GetVersionEx(&VersionInfo) != 0)
32 && (VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
33 }
34 if (supports_MoveFileEx > 0)
35 ok = MoveFileEx(String_val(path1), String_val(path2),
36 MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH |
37 MOVEFILE_COPY_ALLOWED);
38 else
39 ok = MoveFile(String_val(path1), String_val(path2));
40 if (! ok) {
41 win32_maperr(GetLastError());
42 uerror("rename", path1);
43 }
44 return Val_unit;
45 }
46