summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--otherlibs/win32unix/stat.c27
-rw-r--r--otherlibs/win32unix/unix.ml6
2 files changed, 31 insertions, 2 deletions
diff --git a/otherlibs/win32unix/stat.c b/otherlibs/win32unix/stat.c
index a0ba3ca8d..313882a52 100644
--- a/otherlibs/win32unix/stat.c
+++ b/otherlibs/win32unix/stat.c
@@ -86,3 +86,30 @@ CAMLprim value unix_stat_64(value path)
return stat_aux(1, &buf);
}
+CAMLprim value unix_fstat(value handle)
+{
+ int ret;
+ struct _stati64 buf;
+
+ ret = _fstati64(win_CRT_fd_of_filedescr(handle), &buf);
+ if (ret == -1) uerror("fstat", Nothing);
+ if (buf.st_size > Max_long) {
+ win32_maperr(ERROR_ARITHMETIC_OVERFLOW);
+ uerror("fstat", Nothing);
+ }
+ return stat_aux(0, &buf);
+}
+
+CAMLprim value unix_fstat_64(value handle)
+{
+ int ret;
+ struct _stati64 buf;
+
+ ret = _fstati64(win_CRT_fd_of_filedescr(handle), &buf);
+ if (ret == -1) uerror("fstat", Nothing);
+ if (buf.st_size > Max_long) {
+ win32_maperr(ERROR_ARITHMETIC_OVERFLOW);
+ uerror("fstat", Nothing);
+ }
+ return stat_aux(1, &buf);
+}
diff --git a/otherlibs/win32unix/unix.ml b/otherlibs/win32unix/unix.ml
index ee7d6456e..acb12d695 100644
--- a/otherlibs/win32unix/unix.ml
+++ b/otherlibs/win32unix/unix.ml
@@ -242,7 +242,9 @@ type stats =
external stat : string -> stats = "unix_stat"
let lstat = stat
-let fstat fd = invalid_arg "Unix.fstat not implemented"
+external fstat : file_descr -> stats = "unix_fstat"
+let isatty fd =
+ match (fstat fd).st_kind with S_CHR -> true | _ -> false
(* Operations on file names *)
@@ -273,7 +275,7 @@ module LargeFile =
}
external stat : string -> stats = "unix_stat_64"
let lstat = stat
- let fstat fd = invalid_arg "Unix.LargeFile.fstat not implemented"
+ external fstat : file_descr -> stats = "unix_fstat_64"
end
(* File permissions and ownership *)