コード例 #1
0
ファイル: qread.c プロジェクト: Azarien/open-watcom-v2
static tiny_ret_t __TinyRead( int handle, char *buffer, unsigned len )
{
    unsigned    total = 0;
    unsigned    readamt;
    tiny_ret_t  rc;

    while( len > 0 ) {

        if( len > MAXBUFF ) {
            readamt = MAXBUFF;
        } else {
            readamt = len;
        }
        rc = TinyRead( handle, buffer, readamt );
        if( TINY_ERROR( rc ) )
            return( rc );
        total += TINY_LINFO( rc );
        if( TINY_LINFO( rc ) != readamt )
            return( total );

        len -= readamt;
        buffer += readamt;

    }
    return( total );
}
コード例 #2
0
ファイル: qwrit.c プロジェクト: Ukusbobra/open-watcom-v2
static tiny_ret_t __TinyWrite( int handle, const void *buffer, unsigned len )
{
    unsigned    total = 0;
    unsigned    writamt;
    tiny_ret_t  rc;

    while( len > 0 ) {

        if( len > MAXBUFF ) {
            writamt = MAXBUFF;
        } else {
            writamt = len;
        }
        rc = TinyWrite( handle, buffer, writamt );
        if( TINY_ERROR( rc ) )
            return( rc );
        total += TINY_LINFO( rc );
        if( TINY_LINFO( rc ) != writamt )
            return( total );

        len -= writamt;
        buffer = ((const char *)buffer) + writamt;

    }
    return( total );
}
コード例 #3
0
ファイル: qread.c プロジェクト: Azarien/open-watcom-v2
int __qread( int handle, void *buffer, unsigned len )
{
#if defined( __NT__ )
    DWORD           amount_read;
#elif defined(__OS2__)
    OS_UINT         amount_read;
    APIRET          rc;
#else
    unsigned        amount_read;
    tiny_ret_t      rc;
#endif

    __handle_check( handle, -1 );
#ifdef DEFAULT_WINDOWING
    if( _WindowsStdin != NULL ) {
        LPWDATA res;

        res = _WindowsIsWindowedHandle( handle );
        if( res ) {
            int rt;
            rt = _WindowsStdin( res, buffer, len );
            return( rt );
        }
    }
#endif
#if defined(__NT__)
    if( !ReadFile( __getOSHandle( handle ), buffer, len, &amount_read, NULL ) ) {
        DWORD       err;
        err = GetLastError();
        __set_errno_dos( err );
        if( err != ERROR_BROKEN_PIPE || amount_read != 0 ) {
            return( -1 );
        }
    }
#elif defined(__OS2__)
    rc = DosRead( handle, buffer, len, &amount_read );
    if( rc ) {
        return( __set_errno_dos( rc ) );
    }
#else
  #if defined( __WINDOWS_386__ )
    rc = __TinyRead( handle, buffer, len );
  #else
    rc = TinyRead( handle, buffer, len );
  #endif
    if( TINY_ERROR( rc ) ) {
        return( __set_errno_dos( TINY_INFO( rc ) ) );
    }
    amount_read = TINY_LINFO( rc );
#endif
    return( amount_read );
}
コード例 #4
0
ファイル: write.c プロジェクト: Ukusbobra/open-watcom-v2
static int os_write( int handle, const void *buffer, unsigned len, unsigned *amt )
/********************************************************************************/
{
#ifdef DEFAULT_WINDOWING
    LPWDATA     res;
#endif
#if defined(__NT__)
    HANDLE      h;
    int         rc;
#else
    tiny_ret_t  rc;
#endif

    rc = 0;
#ifdef DEFAULT_WINDOWING
    if( _WindowsStdout != 0 && (res = _WindowsIsWindowedHandle( handle )) != 0 ) {
        *amt = _WindowsStdout( res, buffer, len );
    } else
#endif
    {
#if defined(__NT__)
        h = __getOSHandle( handle );
        if( !WriteFile( h, (LPCVOID)buffer, (DWORD)len, (LPDWORD)amt, NULL ) ) {
            rc = __set_errno_nt();
        }
#elif defined(__OS2_286__)
        rc = DosWrite( handle, (PVOID)buffer, (USHORT)len, (PUSHORT)amt );
#elif defined(__OS2__)
        rc = DosWrite( handle, (PVOID)buffer, (ULONG)len, (PULONG)amt );
#else
        rc = TinyWrite( handle, buffer, len );
        *amt = TINY_LINFO( rc );
        if( TINY_OK( rc ) ) {
            rc = 0;
        }
#endif
    }
#if !defined(__NT__)
    if( TINY_ERROR( rc ) ) {
        rc = __set_errno_dos( TINY_INFO( rc ) );
    }
#endif
    if( *amt != len ) {
        rc = ENOSPC;
        __set_errno( rc );
    }
    return( rc );
}
コード例 #5
0
ファイル: write.c プロジェクト: joncampbell123/open-watcom-v2
static int os_write( int handle, const void *buffer, unsigned len, unsigned *amt )
/********************************************************************************/
{
    int         rc;
#ifdef DEFAULT_WINDOWING
    LPWDATA     res;
#endif
#if defined(__NT__)
    HANDLE      h;
#elif defined(__OS2__)
    APIRET      rc1;
#else
    tiny_ret_t  rc1;
#endif

    rc = 0;
#ifdef DEFAULT_WINDOWING
    if( _WindowsStdout != NULL && (res = _WindowsIsWindowedHandle( handle )) != NULL ) {
        *amt = _WindowsStdout( res, buffer, len );
    } else
#endif
    {
#if defined(__NT__)
        h = __getOSHandle( handle );
        if( !WriteFile( h, (LPCVOID)buffer, (DWORD)len, (LPDWORD)amt, NULL ) ) {
            return( __set_errno_nt() );
        }
#elif defined(__OS2__)
        rc1 = DosWrite( handle, (PVOID)buffer, (OS_UINT)len, (OS_PUINT)amt );
        if( rc1 ) {
            return( __set_errno_dos( rc1 ) );
        }
#else
        rc1 = TinyWrite( handle, buffer, len );
        if( TINY_ERROR( rc1 ) ) {
            return( __set_errno_dos( TINY_INFO( rc1 ) ) );
        }
        *amt = TINY_LINFO( rc1 );
#endif
    }
    if( *amt != len ) {
        rc = ENOSPC;
        _RWD_errno = rc;
    }
    return( rc );
}
コード例 #6
0
ファイル: qwrit.c プロジェクト: Ukusbobra/open-watcom-v2
int __qwrite( int handle, const void *buffer, unsigned len )
{
    int             atomic;
#if defined(__NT__)
    DWORD           len_written;
    HANDLE          h;
    int             error;
#elif defined(__WARP__)
    ULONG           len_written;
#elif defined(__OS2_286__)
    USHORT          len_written;
#else
    unsigned        len_written;
#endif
#if !defined(__NT__)
    tiny_ret_t      rc;
#endif

    __handle_check( handle, -1 );

#if defined(__NT__)
    h = __getOSHandle( handle );
#endif
    atomic = 0;
    if( __GetIOMode( handle ) & _APPEND ) {
        _AccessFileH( handle );
        atomic = 1;
#if defined(__NT__)
        if( SetFilePointer( h, 0, NULL, FILE_END ) == -1 ) {
            error = GetLastError();
            _ReleaseFileH( handle );
            return( __set_errno_dos( error ) );
        }
#elif defined(__OS2__)
        {
            unsigned long       dummy;
            rc = DosChgFilePtr( handle, 0L, SEEK_END, &dummy );
        }
#else
        rc = TinySeek( handle, 0L, SEEK_END );
#endif
#if !defined(__NT__)
        if( TINY_ERROR( rc ) ) {
            _ReleaseFileH( handle );
            return( __set_errno_dos( TINY_INFO( rc ) ) );
        }
#endif
    }
#ifdef DEFAULT_WINDOWING
    if( _WindowsStdout != 0 ) {
        LPWDATA res;

        res = _WindowsIsWindowedHandle( handle );
        if( res ) {
            int rt;
            rt = _WindowsStdout( res, buffer, len );
            return( rt );
        }
    }
#endif
#if defined(__NT__)
    if( !WriteFile( h, buffer, len, &len_written, NULL ) ) {
        error = GetLastError();
        if( atomic == 1 ) {
            _ReleaseFileH( handle );
        }
        return( __set_errno_dos( error ) );
    }
#elif defined(__OS2__)
    rc = DosWrite( handle, (PVOID)buffer, len, &len_written );
#elif defined(__WINDOWS_386__)
    rc = __TinyWrite( handle, buffer, len );
    len_written = TINY_LINFO( rc );
#else
    rc = TinyWrite( handle, buffer, len );
    len_written = TINY_LINFO( rc );
#endif
#if !defined(__NT__)
    if( TINY_ERROR( rc ) ) {
        if( atomic == 1 ) {
            _ReleaseFileH( handle );
        }
        return( __set_errno_dos( TINY_INFO( rc ) ) );
    }
#endif
    if( len_written != len ) {
        __set_errno( ENOSPC );
    }
    if( atomic == 1 ) {
        _ReleaseFileH( handle );
    }
    return( len_written );
}
コード例 #7
0
ファイル: read.c プロジェクト: Graham-stott/open-watcom-v2
  _WCRTLINK int read( int handle, void *buf, unsigned len )
#endif
{
    unsigned read_len, total_len;
    unsigned reduce_idx, finish_idx;
    unsigned iomode_flags;
    char *buffer = buf;
#if defined(__NT__)
    DWORD   amount_read;
    BOOL    rc;
    HANDLE  h;
#elif defined(__WARP__)
    ULONG amount_read;
#elif defined(__OS2_286__)
    USHORT amount_read;
#else
    unsigned amount_read;
#endif
#if !defined(__NT__)
    tiny_ret_t rc;
#endif
#ifdef DEFAULT_WINDOWING
    LPWDATA res;
#endif

    __handle_check( handle, -1 );
    __ChkTTYIOMode( handle );
    iomode_flags = __GetIOMode( handle );
    if( iomode_flags == 0 ) {
#if defined( __WINDOWS__ ) || defined( __WINDOWS_386__ )
        return( _lread( handle, buffer, len ) );
#else
        _RWD_errno = EBADF;
        return( -1 );
#endif
    }
    if( !(iomode_flags & _READ) ) {
        _RWD_errno = EACCES;     /* changed from EBADF to EACCES 23-feb-89 */
        return( -1 );
    }
#ifdef __NT__
    h = __getOSHandle( handle );
#endif
    if( iomode_flags & _BINARY ) {       /* if binary mode */
#ifdef DEFAULT_WINDOWING
        if( _WindowsStdin != 0 &&
                (res = _WindowsIsWindowedHandle( handle )) != 0 ) {
            total_len = _WindowsStdin( res, buffer, len );
            rc = 0;
        } else
#endif
        {
#if defined(__NT__)
            rc = ReadFile( h, buffer, len, &amount_read, NULL );
            total_len = amount_read;
            if( !rc ) {
                if (GetLastError() == ERROR_BROKEN_PIPE)
                    return total_len;

                return( __set_errno_nt() );
            }
#elif defined( __OS2__ )
            rc = DosRead( handle, buffer, len, &amount_read );
            total_len = amount_read;
#else
            rc = TinyRead( handle, buffer, len );
            total_len = TINY_LINFO( rc );
#endif
        }
#if !defined(__NT__)
        if( TINY_ERROR( rc ) ) {
            return( __set_errno_dos( TINY_INFO( rc ) ) );
        }
#endif
    } else {
        _AccessFileH( handle );
        total_len = 0;
        read_len = len;
        do {
#ifdef DEFAULT_WINDOWING
            if( _WindowsStdin != 0 &&
                    (res = _WindowsIsWindowedHandle( handle )) != 0L ) {
                amount_read = _WindowsStdin( res, buffer, read_len );
                rc = 0;
            } else
#endif
            {
#if defined(__NT__)
                rc = ReadFile( h, buffer, read_len, &amount_read, NULL );
                if( !rc ) {
                    _ReleaseFileH( handle );

                    if( GetLastError() == ERROR_BROKEN_PIPE )
                        return total_len;

                    return( __set_errno_nt() );
                }
#elif defined( __OS2__ )
                rc = DosRead( handle, buffer, read_len, &amount_read );
#else
                rc = TinyRead( handle, buffer, read_len );
                amount_read = TINY_LINFO( rc );
#endif
            }
#if !defined(__NT__)
            if( TINY_ERROR( rc ) ) {
                _ReleaseFileH( handle );
                return( __set_errno_dos( TINY_INFO( rc ) ) );
            }
#endif
            if( amount_read == 0 ) {                    /* EOF */
                break;
            }
            reduce_idx = 0;
            finish_idx = reduce_idx;
            for( ; reduce_idx < amount_read; ++reduce_idx ) {
                if( buffer[ reduce_idx ] == 0x1a ) {    /* EOF */
                    __lseek( handle,
                           ((long)reduce_idx - (long)amount_read)+1L,
                           SEEK_CUR );
                    total_len += finish_idx;
                    _ReleaseFileH( handle );
                    return( total_len );
                }
                if( buffer[ reduce_idx ] != '\r' ) {
                    buffer[ finish_idx++ ] = buffer[ reduce_idx ];
                }
            }
            total_len += finish_idx;
            buffer += finish_idx;
            read_len -= finish_idx;
            if( iomode_flags & _ISTTY ) {
                break;  /* 04-feb-88, FWC */
            }
        } while( read_len != 0 );
        _ReleaseFileH( handle );
    }
    return( total_len );
}