summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/lseek.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2002-03-06 16:55:20 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2002-03-06 16:55:20 +0000
commit29f80bf5d5ed951e088a1c00847ea7038e15f038 (patch)
tree1cab0ba03c3f6ed38bbfd2d91791da0ff32f722d /otherlibs/win32unix/lseek.c
parente5ba68d5564052bc1f09c5654b994fa0d4b79792 (diff)
Ajout primitives LargeFile
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4486 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix/lseek.c')
-rw-r--r--otherlibs/win32unix/lseek.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/otherlibs/win32unix/lseek.c b/otherlibs/win32unix/lseek.c
index 9544268cf..06f636fe3 100644
--- a/otherlibs/win32unix/lseek.c
+++ b/otherlibs/win32unix/lseek.c
@@ -28,14 +28,48 @@ static int seek_command_table[] = {
FILE_BEGIN, FILE_CURRENT, FILE_END
};
+#ifndef INVALID_SET_FILE_POINTER
+#define INVALID_SET_FILE_POINTER (-1)
+#endif
+
CAMLprim value unix_lseek(value fd, value ofs, value cmd)
{
long ret;
- ret = SetFilePointer(Handle_val(fd), Long_val(ofs), NULL,
+ long ofs_low = Long_val(ofs);
+ long ofs_high = ofs_low >= 0 ? 0 : -1;
+ long err;
+
+ ret = SetFilePointer(Handle_val(fd), ofs_low, &ofs_high,
seek_command_table[Int_val(cmd)]);
- if (ret == -1) {
- win32_maperr(GetLastError());
+ if (ret == INVALID_SET_FILE_POINTER) {
+ err = GetLastError();
+ if (err != NO_ERROR) {
+ win32_maperr(err);
+ uerror("lseek", Nothing);
+ }
+ }
+ if (ofs_high != 0 || ret > Max_long) {
+ win32_maperr(ERROR_ARITHMETIC_OVERFLOW);
uerror("lseek", Nothing);
}
return Val_long(ret);
}
+
+CAMLprim value unix_lseek_64(value fd, value ofs, value cmd)
+{
+ long ret;
+ long ofs_low = (long) Int64_val(ofs);
+ long ofs_high = (long) (Int64_val(ofs) >> 32);
+ long err;
+
+ ret = SetFilePointer(Handle_val(fd), ofs_low, &ofs_high,
+ seek_command_table[Int_val(cmd)]);
+ if (ret == INVALID_SET_FILE_POINTER) {
+ err = GetLastError();
+ if (err != NO_ERROR) {
+ win32_maperr(err);
+ uerror("lseek", Nothing);
+ }
+ }
+ return copy_int64(ofs_high << 32 | ret);
+}