Exemple #1
0
_WCRTLINK int dup( int old_hid )
{
    HANDLE      new_handle;
    int         hid;
    HANDLE      cprocess;

    __handle_check( old_hid, -1 );

    // First try to get the required slot.
    // No point in creating a new handle only to not use it.  JBS 99/11/01
    hid = __allocPOSIXHandle( DUMMY_HANDLE );
    if( hid == -1 ) {
        return( -1 );
    }

    cprocess = GetCurrentProcess();

    if( !DuplicateHandle( cprocess,  __getOSHandle( old_hid ), cprocess,
                        &new_handle, 0, TRUE, DUPLICATE_SAME_ACCESS ) ) {
        // Give back the slot we got
        __freePOSIXHandle( hid );
        return( __set_errno_nt() );
    }
    // Now use the slot we got
    __setOSHandle( hid, new_handle );   // JBS 99/11/01
    __SetIOMode( hid, __GetIOMode( old_hid ) );
    return( hid );
}
int __close( int hid )
{
    int         is_closed;
    int         rc;
    HANDLE      h;
#ifdef DEFAULT_WINDOWING
    LPWDATA res;
#endif

    __handle_check( hid, -1 );

    is_closed = 0;
    rc = 0;
    h = __getOSHandle( hid );

    #ifdef DEFAULT_WINDOWING
        if( _WindowsCloseWindow != 0 ) {
            res = _WindowsIsWindowedHandle( hid );
            if( res != NULL ) {
                _WindowsRemoveWindowedHandle( hid );
                _WindowsCloseWindow( res );
                is_closed = 1;
            }
        }
    #endif
    if( !is_closed && !CloseHandle( h ) ) {
        rc = __set_errno_nt();
    }
    __freePOSIXHandle( hid );
    __SetIOMode_nogrow( hid, 0 );
    return( rc );
}
Exemple #3
0
_WCRTLINK unsigned _dos_close( int hid )
{
    HANDLE  h;

    h = __getOSHandle( hid );
    __SetIOMode_nogrow( hid, 0 );
    __freePOSIXHandle( hid );
    if( !CloseHandle( h ) ) {
        return( __set_errno_nt_reterr() );
    }
    return( 0 );
}
Exemple #4
0
_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 );
}