diff options
Diffstat (limited to 'otherlibs/unix/lseek.c')
-rw-r--r-- | otherlibs/unix/lseek.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/otherlibs/unix/lseek.c b/otherlibs/unix/lseek.c index 3f7d8e698..5dfa7e37f 100644 --- a/otherlibs/unix/lseek.c +++ b/otherlibs/unix/lseek.c @@ -13,7 +13,11 @@ /* $Id$ */ +#include <errno.h> +#include <sys/types.h> #include <mlvalues.h> +#include <alloc.h> +#include <io.h> #include "unixsupport.h" #ifdef HAS_UNISTD @@ -24,15 +28,30 @@ #define SEEK_END 2 #endif +#ifndef EOVERFLOW +#define EOVERFLOW ERANGE +#endif + static int seek_command_table[] = { SEEK_SET, SEEK_CUR, SEEK_END }; CAMLprim value unix_lseek(value fd, value ofs, value cmd) { - long ret; + file_offset ret; ret = lseek(Int_val(fd), Long_val(ofs), seek_command_table[Int_val(cmd)]); if (ret == -1) uerror("lseek", Nothing); + if (ret > Max_long) unix_error(EOVERFLOW, "lseek", Nothing); return Val_long(ret); } + +CAMLprim value unix_lseek_64(value fd, value ofs, value cmd) +{ + file_offset ret; + ret = lseek(Int_val(fd), File_offset_val(ofs), + seek_command_table[Int_val(cmd)]); + if (ret == -1) uerror("lseek", Nothing); + return Val_file_offset(ret); +} + |