reactos/reactos/lib/crt/io/dup.c
Gunnar Dalsnes 55fb40a502 ntdll:
-critical.c: catch (more) invalid use
-impl. sscanf (stolen from wine)
crt:
-use native mingw headers and not private copies of them
-converted some routines to using tchar == impl. many missing unicode routines
-impl. sscanf and friends correctly (stolen from wine)
tchar.h:
-added lotsa missin stuff

svn path=/trunk/; revision=13608
2005-02-16 22:29:48 +00:00

40 lines
666 B
C

#include "precomp.h"
#include <io.h>
#include <errno.h>
#include <internal/file.h>
/*
* @implemented
*/
int _dup(int handle)
{
HANDLE hFile;
HANDLE hProcess = GetCurrentProcess();
BOOL result;
int fd;
hFile = (HANDLE)_get_osfhandle(handle);
if (hFile == INVALID_HANDLE_VALUE) {
__set_errno(EBADF);
return -1;
}
result = DuplicateHandle(hProcess,
hFile,
hProcess,
&hFile,
0,
TRUE,
DUPLICATE_SAME_ACCESS);
if (result == FALSE) {
_dosmaperr(GetLastError());
return -1;
}
fd = alloc_fd(hFile, __fileno_getmode(handle));
if (fd < 0)
{
CloseHandle(hFile);
}
return fd;
}