summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/lseek.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2005-02-02 15:52:26 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2005-02-02 15:52:26 +0000
commitaf1d615aa911596b5fff25f754831f2ac83a351c (patch)
treeebe3ddb17e48a6c09999477d4bea2cd986003e08 /otherlibs/win32unix/lseek.c
parent46c4d1845c8a70f1361cad33e3da250d4d287135 (diff)
Nettoyage de l'implementation
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6774 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix/lseek.c')
-rw-r--r--otherlibs/win32unix/lseek.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/otherlibs/win32unix/lseek.c b/otherlibs/win32unix/lseek.c
index acc7b1004..2df3a86dc 100644
--- a/otherlibs/win32unix/lseek.c
+++ b/otherlibs/win32unix/lseek.c
@@ -25,7 +25,7 @@
#define SEEK_END 2
#endif
-static int seek_command_table[] = {
+static DWORD seek_command_table[] = {
FILE_BEGIN, FILE_CURRENT, FILE_END
};
@@ -33,23 +33,27 @@ static int seek_command_table[] = {
#define INVALID_SET_FILE_POINTER (-1)
#endif
-CAMLprim value unix_lseek(value fd, value ofs, value cmd)
+static __int64 caml_set_file_pointer(HANDLE h, __int64 dist, DWORD mode)
{
- long ret;
- long ofs_low = Long_val(ofs);
- long ofs_high = ofs_low >= 0 ? 0 : -1;
- long err;
+ LARGE_INTEGER i;
+ DWORD err;
- ret = SetFilePointer(Handle_val(fd), ofs_low, &ofs_high,
- seek_command_table[Int_val(cmd)]);
- if (ret == INVALID_SET_FILE_POINTER) {
+ i.QuadPart = dist;
+ i.LowPart = SetFilePointer(h, i.LowPart, &i.HighPart, mode);
+ if (i.LowPart == INVALID_SET_FILE_POINTER) {
err = GetLastError();
- if (err != NO_ERROR) {
- win32_maperr(err);
- uerror("lseek", Nothing);
- }
+ if (err != NO_ERROR) { win32_maperr(err); uerror("lseek", Nothing); }
}
- if (ofs_high != 0 || ret > Max_long) {
+ return i.QuadPart;
+}
+
+CAMLprim value unix_lseek(value fd, value ofs, value cmd)
+{
+ __int64 ret;
+
+ ret = caml_set_file_pointer(Handle_val(fd), Long_val(ofs),
+ seek_command_table[Int_val(cmd)]);
+ if (ret > Max_long) {
win32_maperr(ERROR_ARITHMETIC_OVERFLOW);
uerror("lseek", Nothing);
}
@@ -58,19 +62,9 @@ CAMLprim value unix_lseek(value fd, value ofs, value cmd)
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;
+ __int64 ret;
- 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((int64) ofs_high << 32 | ret);
+ ret = caml_set_file_pointer(Handle_val(fd), Int64_val(ofs),
+ seek_command_table[Int_val(cmd)]);
+ return copy_int64(ret);
}