unsigned ReqFile_open( void ) { HANDLE h; file_open_req *acc; file_open_ret *ret; void *buff; unsigned mode; static unsigned const mapAcc[] = { 0, 1, 2 }; acc = GetInPtr( 0 ); buff = GetInPtr( sizeof( *acc ) ); ret = GetOutPtr( 0 ); /* * GetMagicalFileHandle checks if a file name is of a special syntax. * We generate magical file names for all DLL's when they load, * since NT only gives a file handle to the DLL, not a file name. * We fake up a name, and remember the handle. When the debugger * asks to open up a fake name, we reuse the handle */ h = GetMagicalFileHandle( buff ); ret->err = 0; if( h == NULL ) { /* * these __GetNT... routines are in the C library. they turn * DOS style access and share bits into NT style ones */ extern void __GetNTAccessAttr( int rwmode, LPDWORD desired_access, LPDWORD attr ); extern void __GetNTShareAttr( int share, LPDWORD share_mode ); DWORD share_mode; DWORD desired_access; DWORD attr; DWORD create_disp; mode = mapAcc[ ( 0x3 & acc->mode ) - 1]; __GetNTAccessAttr( mode & 0x7, &desired_access, &attr ); __GetNTShareAttr( mode & 0x70, &share_mode ); if( acc->mode & TF_CREATE ) { create_disp = CREATE_ALWAYS; } else { create_disp = OPEN_EXISTING; } h = CreateFile( ( LPTSTR ) buff, desired_access, share_mode, 0, create_disp, FILE_ATTRIBUTE_NORMAL, NULL ); if( h == ( HANDLE ) - 1 ) { ret->err = GetLastError(); h = 0; } } ret->handle = ( DWORD ) h; return( sizeof( *ret ) ); }
_WCRTLINK unsigned _dos_open( const char *name, unsigned mode, int *posix_handle ) { HANDLE handle; unsigned rwmode; DWORD share_mode; DWORD desired_access, os_attr; unsigned iomode_flags; int hid; // First try to get the required slot. // No point in creating a file only to not use it. JBS 99/11/01 hid = __allocPOSIXHandle( DUMMY_HANDLE ); if( hid == -1 ) { return( __set_errno_dos_reterr( ERROR_NOT_ENOUGH_MEMORY ) ); } rwmode = mode & OPENMODE_ACCESS_MASK; __GetNTAccessAttr( rwmode, &desired_access, &os_attr ); __GetNTShareAttr( mode & (OPENMODE_SHARE_MASK|OPENMODE_ACCESS_MASK), &share_mode ); handle = CreateFile( (LPTSTR) name, desired_access, share_mode, 0, OPEN_EXISTING, os_attr, NULL ); if( handle == (HANDLE)-1 ) { __freePOSIXHandle( hid ); return( __set_errno_nt_reterr() ); } // Now use the slot we got. __setOSHandle( hid, handle ); // JBS 99/11/01 *posix_handle = hid; iomode_flags = 0; if( rwmode == O_RDWR ) iomode_flags = _READ | _WRITE; if( rwmode == O_RDONLY ) iomode_flags = _READ; if( rwmode == O_WRONLY ) iomode_flags = _WRITE; __SetIOMode( hid, iomode_flags ); return( 0 ); }