1997-09-03 07:38:02 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* 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>
|
1997-11-17 09:15:28 -08:00
|
|
|
#include <alloc.h>
|
1997-09-03 07:38:02 -07:00
|
|
|
#include "unixsupport.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2003-01-06 06:52:57 -08:00
|
|
|
extern long _get_osfhandle(int);
|
|
|
|
extern int _open_osfhandle(long, int);
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value win_fd_handle(value handle)
|
1997-09-03 07:38:02 -07:00
|
|
|
{
|
2003-01-06 06:52:57 -08:00
|
|
|
int fd;
|
|
|
|
if (CRT_fd_val(handle) != NO_CRT_FD) {
|
|
|
|
fd = CRT_fd_val(handle);
|
|
|
|
} else {
|
|
|
|
fd = _open_osfhandle((long) Handle_val(handle), O_BINARY);
|
|
|
|
if (fd == -1) uerror("channel_of_descr", Nothing);
|
|
|
|
CRT_fd_val(handle) = fd;
|
|
|
|
}
|
1997-09-04 06:45:56 -07:00
|
|
|
return Val_int(fd);
|
1997-09-03 07:38:02 -07:00
|
|
|
}
|
|
|
|
|
2003-01-06 06:52:57 -08:00
|
|
|
CAMLprim value win_handle_fd(value vfd)
|
1997-09-03 07:38:02 -07:00
|
|
|
{
|
2003-01-06 06:52:57 -08:00
|
|
|
int crt_fd = Int_val(vfd);
|
|
|
|
value res = win_alloc_handle_or_socket((HANDLE) _get_osfhandle(crt_fd));
|
|
|
|
CRT_fd_val(res) = crt_fd;
|
|
|
|
return res;
|
1997-09-03 07:38:02 -07:00
|
|
|
}
|