1 /***********************************************************************/
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../../LICENSE. */
12 /***********************************************************************/
14 /* $Id: lseek.c 6774 2005-02-02 15:52:26Z xleroy $ */
18 #include "unixsupport.h"
28 static DWORD seek_command_table[] = {
29 FILE_BEGIN, FILE_CURRENT, FILE_END
32 #ifndef INVALID_SET_FILE_POINTER
33 #define INVALID_SET_FILE_POINTER (-1)
36 static __int64 caml_set_file_pointer(HANDLE h, __int64 dist, DWORD mode)
42 i.LowPart = SetFilePointer(h, i.LowPart, &i.HighPart, mode);
43 if (i.LowPart == INVALID_SET_FILE_POINTER) {
45 if (err != NO_ERROR) { win32_maperr(err); uerror("lseek", Nothing); }
50 CAMLprim value unix_lseek(value fd, value ofs, value cmd)
54 ret = caml_set_file_pointer(Handle_val(fd), Long_val(ofs),
55 seek_command_table[Int_val(cmd)]);
57 win32_maperr(ERROR_ARITHMETIC_OVERFLOW);
58 uerror("lseek", Nothing);
63 CAMLprim value unix_lseek_64(value fd, value ofs, value cmd)
67 ret = caml_set_file_pointer(Handle_val(fd), Int64_val(ofs),
68 seek_command_table[Int_val(cmd)]);
69 return copy_int64(ret);