-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Binds to realpath(3) on POSIX and GetFinalPathNameByHandle on Windows.
- Loading branch information
Showing
12 changed files
with
145 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/**************************************************************************/ | ||
/* */ | ||
/* OCaml */ | ||
/* */ | ||
/* The OCaml programmers */ | ||
/* */ | ||
/* Copyright 2020 Institut National de Recherche en Informatique et */ | ||
/* en Automatique. */ | ||
/* */ | ||
/* All rights reserved. This file is distributed under the terms of */ | ||
/* the GNU Lesser General Public License version 2.1, with the */ | ||
/* special exception on linking described in the file LICENSE. */ | ||
/* */ | ||
/**************************************************************************/ | ||
|
||
#include <caml/mlvalues.h> | ||
#include <caml/memory.h> | ||
#include <caml/alloc.h> | ||
#include <caml/fail.h> | ||
#include "unixsupport.h" | ||
|
||
#ifdef HAS_REALPATH | ||
|
||
CAMLprim value unix_realpath (value p) | ||
{ | ||
CAMLparam1 (p); | ||
char *r; | ||
value rp; | ||
|
||
caml_unix_check_path (p, "realpath"); | ||
r = realpath (String_val (p), NULL); | ||
if (r == NULL) { uerror ("realpath", p); } | ||
rp = caml_copy_string (r); | ||
free (r); | ||
CAMLreturn (rp); | ||
} | ||
|
||
#else | ||
|
||
CAMLprim value unix_realpath (value p) | ||
{ caml_invalid_argument ("realpath not implemented"); } | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/**************************************************************************/ | ||
/* */ | ||
/* OCaml */ | ||
/* */ | ||
/* The OCaml programmers */ | ||
/* */ | ||
/* Copyright 2020 Institut National de Recherche en Informatique et */ | ||
/* en Automatique. */ | ||
/* */ | ||
/* All rights reserved. This file is distributed under the terms of */ | ||
/* the GNU Lesser General Public License version 2.1, with the */ | ||
/* special exception on linking described in the file LICENSE. */ | ||
/* */ | ||
/**************************************************************************/ | ||
|
||
#define CAML_INTERNALS | ||
|
||
#include <caml/mlvalues.h> | ||
#include <caml/memory.h> | ||
#include <caml/alloc.h> | ||
#include <caml/fail.h> | ||
#include <caml/osdeps.h> | ||
#include "unixsupport.h" | ||
|
||
#include <windows.h> | ||
#include <fileapi.h> | ||
#include <stdio.h> | ||
|
||
CAMLprim value unix_realpath (value p) | ||
{ | ||
CAMLparam1 (p); | ||
HANDLE h; | ||
wchar_t *wp; | ||
wchar_t *wr; | ||
DWORD wr_len; | ||
value rp; | ||
|
||
caml_unix_check_path (p, "realpath"); | ||
wp = caml_stat_strdup_to_utf16 (String_val (p)); | ||
h = CreateFile (wp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, | ||
FILE_ATTRIBUTE_NORMAL, NULL); | ||
caml_stat_free (wp); | ||
|
||
if (h == INVALID_HANDLE_VALUE) | ||
{ | ||
win32_maperr (GetLastError ()); | ||
uerror ("realpath", p); | ||
} | ||
|
||
wr_len = GetFinalPathNameByHandle (h, NULL, 0, VOLUME_NAME_DOS); | ||
if (wr_len == 0) | ||
{ | ||
win32_maperr (GetLastError ()); | ||
CloseHandle (h); | ||
uerror ("realpath", p); | ||
} | ||
|
||
wr = caml_stat_alloc ((wr_len + 1) * sizeof (wchar_t)); | ||
wr_len = GetFinalPathNameByHandle (h, wr, wr_len, VOLUME_NAME_DOS); | ||
|
||
if (wr_len == 0) | ||
{ | ||
win32_maperr (GetLastError ()); | ||
CloseHandle (h); | ||
caml_stat_free (wr); | ||
uerror ("realpath", p); | ||
} | ||
|
||
rp = caml_copy_string_of_utf16 (wr); | ||
CloseHandle (h); | ||
caml_stat_free (wr); | ||
CAMLreturn (rp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters