1 /**************************************************************************/
2 /*                                                                        */
3 /*                                 OCaml                                  */
4 /*                                                                        */
5 /*                  File contributed by Lionel Fourquaux                  */
6 /*                                                                        */
7 /*   Copyright 2001 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 <caml/mlvalues.h>
17 #include <caml/fail.h>
18 #include "unixsupport.h"
19 #include <windows.h>
20 
21 typedef
22 BOOL (WINAPI *tCreateHardLink)(
23   LPCTSTR lpFileName,
24   LPCTSTR lpExistingFileName,
25   LPSECURITY_ATTRIBUTES lpSecurityAttributes
26 );
27 
unix_link(value path1,value path2)28 CAMLprim value unix_link(value path1, value path2)
29 {
30   HMODULE hModKernel32;
31   tCreateHardLink pCreateHardLink;
32   hModKernel32 = GetModuleHandle("KERNEL32.DLL");
33   pCreateHardLink =
34     (tCreateHardLink) GetProcAddress(hModKernel32, "CreateHardLinkA");
35   if (pCreateHardLink == NULL)
36     caml_invalid_argument("Unix.link not implemented");
37   caml_unix_check_path(path1, "link");
38   caml_unix_check_path(path2, "link");
39   if (! pCreateHardLink(String_val(path2), String_val(path1), NULL)) {
40     win32_maperr(GetLastError());
41     uerror("link", path2);
42   }
43   return Val_unit;
44 }
45