static int open_base( const CHAR_TYPE *name, int mode ) { int handle; rdos_handle_type *obj; int rdos_handle; unsigned iomode_flags; int rwmode; rwmode = mode & OPENMODE_ACCESS_MASK; iomode_flags = 0; if( mode == O_RDWR ) iomode_flags |= _READ | _WRITE; if( rwmode == O_RDONLY) iomode_flags |= _READ; if( rwmode == O_WRONLY) iomode_flags |= _WRITE; if( mode & O_APPEND ) iomode_flags |= _APPEND; if( mode & (O_BINARY|O_TEXT) ) if( mode & O_BINARY ) iomode_flags |= _BINARY; rdos_handle = RdosOpenKernelFile( name, mode ); if( rdos_handle ) { obj = AllocHandleObj( name ); if( obj ) { obj->rdos_handle = rdos_handle; obj->mode = iomode_flags; obj->pos = 0; handle = AllocHandleEntry( obj ); return( handle ); } } return( -1 ); }
static int open_base( const CHAR_TYPE *name, int mode ) { int handle; rdos_handle_type *obj; int rdos_handle; int rwmode; unsigned iomode_flags; rwmode = mode & OPENMODE_ACCESS_MASK; iomode_flags = 0; if( mode == O_RDWR ) iomode_flags |= _READ | _WRITE; if( rwmode == O_RDONLY) iomode_flags |= _READ; if( rwmode == O_WRONLY) iomode_flags |= _WRITE; if( mode & O_APPEND ) iomode_flags |= _APPEND; if( mode & (O_BINARY|O_TEXT) ) if( mode & O_BINARY ) iomode_flags |= _BINARY; if( !strcmp( name, CONSOLE ) ) { if( mode & O_CREAT ) obj = console_out; else obj = console_in; obj->ref_count++; handle = AllocHandleEntry( obj ); return( handle ); } else { if( mode & O_CREAT ) { if( mode & O_EXCL ) { rdos_handle = RdosOpenFile( name, 0 ); if( rdos_handle ) { RdosCloseFile( rdos_handle ); return( -1 ); } } rdos_handle = RdosCreateFile( name, 0 ); } else rdos_handle = RdosOpenFile( name, 0 ); if( rdos_handle ) if( mode & O_TRUNC ) RdosSetFileSize( rdos_handle, 0 ); if( rdos_handle ) { obj = AllocHandleObj( name ); if( obj ) { obj->rdos_handle = rdos_handle; obj->mode = iomode_flags; obj->type = HANDLE_TYPE_FILE; handle = AllocHandleEntry( obj ); return( handle ); } } } return( -1 ); }
static void InitHandle( void ) { int i; rdos_handle_type *h; const char *inherit; const char *ptr; handle_section = RdosCreateSection( "Watcom.Handle" ); handle_count = 5; handle_ptr = ( rdos_handle_type ** )lib_malloc( handle_count * sizeof( rdos_handle_type * ) ); for( i = 0; i < handle_count; i++ ) handle_ptr[i] = 0; h = AllocHandleObj( 0 ); h->type = HANDLE_TYPE_INPUT; h->mode = _READ; handle_ptr[0] = h; h->ref_count++; console_in = h; h = AllocHandleObj( 0 ); h->type = HANDLE_TYPE_OUTPUT; h->mode = _WRITE; handle_ptr[1] = h; h->ref_count++; console_out = h; h->ref_count++; handle_ptr[2] = h; inherit = RdosGetOptions(); if( inherit ) ProcessInherit( inherit ); }
static void ProcessFile( char *filename, int handle, unsigned mode ) { rdos_handle_type *obj; int rdos_handle; int org_handle; rdos_handle = RdosOpenFile( filename, 0 ); if( rdos_handle ) { obj = AllocHandleObj( filename ); } if( obj ) { obj->rdos_handle = rdos_handle; obj->mode = mode; obj->type = HANDLE_TYPE_FILE; org_handle = AllocHandleEntry( obj ); dup2( org_handle, handle ); close( org_handle ); } }