1997-09-03 07:38:02 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
2011-07-27 07:17:02 -07:00
|
|
|
/* OCaml */
|
1997-09-03 07:38:02 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1997-09-03 07:38:02 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <mlvalues.h>
|
2002-06-07 02:49:45 -07:00
|
|
|
#include <alloc.h>
|
1997-09-03 07:38:02 -07:00
|
|
|
#include "unixsupport.h"
|
|
|
|
|
|
|
|
#ifdef HAS_UNISTD
|
|
|
|
#include <unistd.h>
|
|
|
|
#else
|
|
|
|
#define SEEK_SET 0
|
|
|
|
#define SEEK_CUR 1
|
|
|
|
#define SEEK_END 2
|
|
|
|
#endif
|
|
|
|
|
2005-02-02 07:52:26 -08:00
|
|
|
static DWORD seek_command_table[] = {
|
1997-09-03 07:38:02 -07:00
|
|
|
FILE_BEGIN, FILE_CURRENT, FILE_END
|
|
|
|
};
|
|
|
|
|
2002-03-06 08:55:20 -08:00
|
|
|
#ifndef INVALID_SET_FILE_POINTER
|
|
|
|
#define INVALID_SET_FILE_POINTER (-1)
|
|
|
|
#endif
|
|
|
|
|
2005-02-02 07:52:26 -08:00
|
|
|
static __int64 caml_set_file_pointer(HANDLE h, __int64 dist, DWORD mode)
|
1997-09-03 07:38:02 -07:00
|
|
|
{
|
2005-02-02 07:52:26 -08:00
|
|
|
LARGE_INTEGER i;
|
|
|
|
DWORD err;
|
2002-03-06 08:55:20 -08:00
|
|
|
|
2005-02-02 07:52:26 -08:00
|
|
|
i.QuadPart = dist;
|
|
|
|
i.LowPart = SetFilePointer(h, i.LowPart, &i.HighPart, mode);
|
|
|
|
if (i.LowPart == INVALID_SET_FILE_POINTER) {
|
2002-03-06 08:55:20 -08:00
|
|
|
err = GetLastError();
|
2005-02-02 07:52:26 -08:00
|
|
|
if (err != NO_ERROR) { win32_maperr(err); uerror("lseek", Nothing); }
|
2002-03-06 08:55:20 -08:00
|
|
|
}
|
2005-02-02 07:52:26 -08:00
|
|
|
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),
|
2010-01-22 04:48:24 -08:00
|
|
|
seek_command_table[Int_val(cmd)]);
|
2005-02-02 07:52:26 -08:00
|
|
|
if (ret > Max_long) {
|
2002-03-06 08:55:20 -08:00
|
|
|
win32_maperr(ERROR_ARITHMETIC_OVERFLOW);
|
1997-09-03 07:38:02 -07:00
|
|
|
uerror("lseek", Nothing);
|
|
|
|
}
|
|
|
|
return Val_long(ret);
|
|
|
|
}
|
2002-03-06 08:55:20 -08:00
|
|
|
|
|
|
|
CAMLprim value unix_lseek_64(value fd, value ofs, value cmd)
|
|
|
|
{
|
2005-02-02 07:52:26 -08:00
|
|
|
__int64 ret;
|
2002-03-06 08:55:20 -08:00
|
|
|
|
2005-02-02 07:52:26 -08:00
|
|
|
ret = caml_set_file_pointer(Handle_val(fd), Int64_val(ofs),
|
2010-01-22 04:48:24 -08:00
|
|
|
seek_command_table[Int_val(cmd)]);
|
2005-02-02 07:52:26 -08:00
|
|
|
return copy_int64(ret);
|
2002-03-06 08:55:20 -08:00
|
|
|
}
|