diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 5a02a29dcf6..eadde050717 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -1206,24 +1206,9 @@ int _futime(int fd, struct MSVCRT__utimbuf *t) long _get_osfhandle(int fd) { HANDLE hand = msvcrt_fdtoh(fd); - HANDLE newhand = hand; TRACE(":fd (%d) handle (%p)\n",fd,hand); - if (hand != INVALID_HANDLE_VALUE) - { - /* FIXME: I'm not convinced that I should be copying the - * handle here - it may be leaked if the app doesn't - * close it (and the API docs don't say that it should) - * Not duplicating it means that it can't be inherited - * and so lcc's wedit doesn't cope when it passes it to - * child processes. I've an idea that it should either - * be copied by CreateProcess, or marked as inheritable - * when initialised, or maybe both? JG 21-9-00. - */ - DuplicateHandle(GetCurrentProcess(),hand,GetCurrentProcess(), - &newhand,0,TRUE,DUPLICATE_SAME_ACCESS); - } - return (long)newhand; + return (long)hand; } /********************************************************************* diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 9166ee9bbe2..d1a8d7f43ae 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -464,6 +465,24 @@ static void test_fopen_fclose_fcloseall( void ) ok(_unlink(fname3) == 0, "Couldn't unlink file named '%s'\n", fname3); } +static void test_get_osfhandle(void) +{ + int fd; + char fname[] = "t_get_osfhanle"; + DWORD bytes_written; + HANDLE handle; + + fd = _sopen(fname, _O_CREAT|_O_RDWR, _SH_DENYRW, 0); + handle = (HANDLE)_get_osfhandle(fd); + WriteFile(handle, "bar", 3, &bytes_written, NULL); + _close(fd); + fd = _open(fname, _O_RDONLY, 0); + ok(fd != -1, "Coudn't open '%s' after _get_osfhanle()\n", fname); + + CloseHandle(handle); + _unlink(fname); +} + START_TEST(file) { int arg_c; @@ -489,4 +508,5 @@ START_TEST(file) test_fgetwc(); test_file_put_get(); test_tmpnam(); + test_get_osfhandle(); }