msvcrt: Don't duplicate handle in _get_osfhandle.
This commit is contained in:
parent
0dec18a3d6
commit
4f7adfb04a
|
@ -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;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <share.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
#include <windef.h>
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue