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>
|
|
|
|
#include "unixsupport.h"
|
|
|
|
|
2003-01-06 06:52:57 -08:00
|
|
|
extern int _dup2(int, int);
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_dup2(value fd1, value fd2)
|
1997-09-03 07:38:02 -07:00
|
|
|
{
|
|
|
|
HANDLE oldh, newh;
|
|
|
|
|
|
|
|
oldh = Handle_val(fd2);
|
|
|
|
if (! DuplicateHandle(GetCurrentProcess(), Handle_val(fd1),
|
|
|
|
GetCurrentProcess(), &newh,
|
1997-09-04 06:45:56 -07:00
|
|
|
0L, TRUE, DUPLICATE_SAME_ACCESS)) {
|
2001-08-28 07:47:48 -07:00
|
|
|
win32_maperr(GetLastError());
|
1997-09-03 07:38:02 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Handle_val(fd2) = newh;
|
2002-04-30 08:00:48 -07:00
|
|
|
if (Descr_kind_val(fd2) == KIND_SOCKET)
|
|
|
|
closesocket((SOCKET) oldh);
|
|
|
|
else
|
|
|
|
CloseHandle(oldh);
|
|
|
|
Descr_kind_val(fd2) = Descr_kind_val(fd1);
|
2003-01-06 06:52:57 -08:00
|
|
|
/* Reflect the dup2 on the CRT fds, if any */
|
|
|
|
if (CRT_fd_val(fd1) != NO_CRT_FD || CRT_fd_val(fd2) != NO_CRT_FD)
|
2006-09-21 02:43:58 -07:00
|
|
|
_dup2(win_CRT_fd_of_filedescr(fd1), win_CRT_fd_of_filedescr(fd2));
|
1997-09-03 07:38:02 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|