|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++.windows.32-bits - Bug in _open_osfhandle of _fdopen
Below is a code fragment with a bug in either _open_osfhandle or _fdopen.
This fragement runs as expected under the Borland command line tools, but
generates a "Bad file descriptor" error when compiled using the latest sc.
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>
#include <fcntl.h>
#include <io.h>
int main()
{
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
FILE *f = NULL;
int fno, binary_mode;
HANDLE child_out;
HANDLE father_in;
HANDLE father_in_dup;
HANDLE current_pid;
current_pid = GetCurrentProcess();
binary_mode = _O_TEXT | _O_RDONLY;
if (CreatePipe( &father_in, &child_out, &sa, 0) == FALSE) {
fprintf(stderr, "popen: error CreatePipe\n");
exit( 0 );
}
if (DuplicateHandle( current_pid, father_in, current_pid, &father_in_dup,
0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) {
fprintf(stderr, "popen: error DuplicateHandle father_in\n");
exit( 0 );
}
CloseHandle( father_in );
fno = _open_osfhandle( (long) father_in_dup, binary_mode );
// problem is here XXX
perror( "\nBefore\n" );fflush(stdout);
f = _fdopen( fno, "r" );
perror("\nAfter\n");printf( "fno: %ld f: %08lX\n", fno, f );fflush(stdout);
return( 0 );
}
Jun 27 2002
I don't know what's going wrong. I'll add it to the bug list. Thanks. -Walter "Steve Adams" <sadams3 columbus.rr.com> wrote in message news:aff6lc$1crd$1 digitaldaemon.com... Jul 01 2002
|