Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / otherlibs / win32unix / rename.c
blob3bfdf47707791eb79546607cfb44d23912449d6f
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 /***********************************************************************/
14 /* $Id$ */
16 #include <stdio.h>
17 #include <mlvalues.h>
18 #include "unixsupport.h"
20 CAMLprim value unix_rename(value path1, value path2)
22 static int supports_MoveFileEx = -1; /* don't know yet */
23 BOOL ok;
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);
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);
42 return Val_unit;