_WCRTLINK int dup2( int handle1, int handle2 ) { rdos_handle_type *obj = 0; if( handle1 == handle2 ) return( handle2 ); if( handle2 < 0 ) return( -1 ); while( handle2 >= handle_count ) GrowHandleArr( ); RdosEnterKernelSection( &handle_section ); if( handle1 >= 0 && handle1 < handle_count ) if( handle_ptr[handle1] ) obj = handle_ptr[handle1]; if( obj ) obj->ref_count++; RdosLeaveKernelSection( &handle_section ); if( obj ) { if( ReplaceHandleEntry( handle2, obj ) ) return( handle2 ); else obj->ref_count--; } return( -1 ); }
void __SetIOMode_nogrow( int handle, unsigned value ) { RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) if( handle_ptr[handle] ) handle_ptr[handle]->mode = value; RdosLeaveKernelSection( &handle_section ); }
static void SetHandlePos( int handle, long pos ) { RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) { if( handle_ptr[handle] ) { handle_ptr[handle]->pos = pos; } } RdosLeaveKernelSection( &handle_section ); }
unsigned __GetIOMode( int handle ) { unsigned mode = 0; RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) if( handle_ptr[handle] ) mode = handle_ptr[handle]->mode; RdosLeaveKernelSection( &handle_section ); return( mode ); }
signed __SetIOMode( int handle, unsigned value ) { signed ret = -1; RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) if( handle_ptr[handle] ) { handle_ptr[handle]->mode = value; ret = handle; } RdosLeaveKernelSection( &handle_section ); return( ret ); }
static long GetHandlePos( int handle ) { long pos = 0; RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) { if( handle_ptr[handle] ) { pos = handle_ptr[handle]->pos; } } RdosLeaveKernelSection( &handle_section ); return( pos ); }
static int GetHandle( int handle ) { int rdos_handle = -1; RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) { if( handle_ptr[handle] ) { rdos_handle = handle_ptr[handle]->rdos_handle; } } RdosLeaveKernelSection( &handle_section ); return( rdos_handle ); }
static rdos_handle_type *FreeHandleEntry( int handle ) { rdos_handle_type *obj = 0; RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) { if( handle_ptr[handle] ) { obj = handle_ptr[handle]; handle_ptr[handle] = 0; } } RdosLeaveKernelSection( &handle_section ); return( obj ); }
static int AllocHandleEntry( rdos_handle_type *obj ) { int i; RdosEnterKernelSection( &handle_section ); for( i = 0; i < handle_count; i++) if( handle_ptr[i] == 0 ) break; if( i == handle_count ) GrowHandleArr(); handle_ptr[i] = obj; RdosLeaveKernelSection( &handle_section ); return( i ); }
_WCRTLINK int dup( int handle ) { rdos_handle_type *obj = 0; RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) if( handle_ptr[handle] ) obj = handle_ptr[handle]; if( obj ) obj->ref_count++; RdosLeaveKernelSection( &handle_section ); if( obj ) return( AllocHandleEntry( obj ) ); else return( -1 ); }
static int ReplaceHandleEntry( int handle, rdos_handle_type *new_obj ) { int ok = 0; rdos_handle_type *obj = 0; RdosEnterKernelSection( &handle_section ); if( handle >= 0 && handle < handle_count ) { if( handle_ptr[handle] ) obj = handle_ptr[handle]; handle_ptr[handle] = new_obj; ok = 1; } RdosLeaveKernelSection( &handle_section ); if( obj ) FreeHandleObj( obj ); return ( ok ); }
_WCRTLINK void __AccessSemaphore( semaphore_object *obj ) { TID tid; tid = GetCurrentThreadId(); #if defined( _NETWARE_CLIB ) if( tid == 0 ) return; #endif if( obj->owner != tid ) { #if defined( _M_I86 ) DosSemRequest( &obj->semaphore, -1L ); #else #if !defined( __NETWARE__ ) if( obj->initialized == 0 ) { #if defined( __RUNTIME_CHECKS__ ) && defined( _M_IX86 ) if( obj == &InitSemaphore ) { __fatal_runtime_error( "Bad semaphore lock", 1 ); } #endif __AccessSemaphore( &InitSemaphore ); if( obj->initialized == 0 ) { #if defined( __NT__ ) obj->semaphore = __NTGetCriticalSection(); #elif defined( __QNX__ ) __qsem_init( &obj->semaphore, 1, 1 ); #elif defined( __LINUX__ ) // TODO: Access semaphore under Linux! #elif defined( __RDOS__ ) obj->semaphore = RdosCreateSection(); #elif defined( __RDOSDEV__ ) RdosInitKernelSection(&obj->semaphore); #else DosCreateMutexSem( NULL, &obj->semaphore, 0, FALSE ); #endif obj->initialized = 1; } __ReleaseSemaphore( &InitSemaphore ); } #endif #if defined( __NETWARE__ ) while( obj->semaphore != 0 ) { #if defined (_NETWARE_CLIB) ThreadSwitch(); #else NXThreadYield(); #endif } obj->semaphore = 1; obj->initialized = 1; #elif defined( __NT__ ) EnterCriticalSection( obj->semaphore ); #elif defined( __QNX__ ) __qsem_wait( &obj->semaphore ); #elif defined( __LINUX__ ) // TODO: Wait for semaphore under Linux! #elif defined( __RDOS__ ) RdosEnterSection( obj->semaphore ); #elif defined( __RDOSDEV__ ) RdosEnterKernelSection( &obj->semaphore ); #else DosRequestMutexSem( obj->semaphore, SEM_INDEFINITE_WAIT ); #endif #endif obj->owner = tid; } obj->count++; }