Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

static int krdrFileRead ( PKRDR  pRdr,
void *  pvBuf,
KSIZE  cb,
KFOFF  off 
) [static]

Definition at line 994 of file kRdrFile.cpp.

References DWORD, KRDRFILE::File, KERR_GENERAL_FAILURE, NULL, and KRDRFILE::off.

{
    PKRDRFILE pRdrFile = (PKRDRFILE)pRdr;

    /*
     * Do a seek if needed.
     */
    if (pRdrFile->off != off)
    {
#if K_OS == K_OS_DARWIN \
 || K_OS == K_OS_FREEBSD \
 || K_OS == K_OS_LINUX \
 || K_OS == K_OS_NETBSD \
 || K_OS == K_OS_OPENBSD \
 || K_OS == K_OS_SOLARIS
        pRdrFile->off = kHlpSys_lseek(pRdrFile->File, SEEK_SET, off);
        if (pRdrFile->off < 0)
        {
            int rc = (int)-pRdrFile->off;
            pRdrFile->off = -1;
            return -rc;
        }

#elif K_OS == K_OS_OS2
        ULONG ulNew;
        APIRET rc;

        rc = DosSetFilePtr(pRdrFile->File, off, FILE_BEGIN, &ulNew);
        if (rc)
        {
            pRdrFile->off = -1;
            return rc;
        }

#elif K_OS == K_OS_WINDOWS
        LONG offHigh;
        LONG offLow;

        offHigh = (LONG)(off >> 32);
        offLow = SetFilePointer(pRdrFile->File, (LONG)off, &offHigh, FILE_BEGIN);
        if (    offLow != (LONG)off
            ||  offHigh != (LONG)(off >> 32))
        {
            int rc = GetLastError();
            if (!rc)
                rc = KERR_GENERAL_FAILURE;
            pRdrFile->off = -1;
            return rc;
        }

#else
# error "port me."
#endif
    }

    /*
     * Do the read.
     */
#if K_OS == K_OS_DARWIN \
 || K_OS == K_OS_FREEBSD \
 || K_OS == K_OS_LINUX \
 || K_OS == K_OS_NETBSD \
 || K_OS == K_OS_OPENBSD \
 || K_OS == K_OS_SOLARIS
    {
    KSSIZE cbRead;

    cbRead = kHlpSys_read(pRdrFile->File, pvBuf, cb);
    if (cbRead != cb)
    {
        pRdrFile->off = -1;
        if (cbRead < 0)
            return -cbRead;
        return KERR_GENERAL_FAILURE;
    }
    }

#elif K_OS == K_OS_OS2
    {
    ULONG cbRead = 0;
    APIRET rc = DosRead(pRdrFile->File, pvBuf, cb, &cbRead);
    if (rc)
    {
        pRdrFile->off = -1;
        return rc;
    }
    if (cbRead != cb)
    {
        pRdrFile->off = -1;
        return KERR_GENERAL_FAILURE;
    }
    }

#elif K_OS == K_OS_WINDOWS
    {
    DWORD cbRead = 0;
    if (!ReadFile(pRdrFile->File, pvBuf, cb, &cbRead, NULL))
    {
        int rc = GetLastError();
        if (!rc)
            rc = KERR_GENERAL_FAILURE;
        pRdrFile->off = -1;
        return rc;
    }
    if (cbRead != cb)
    {
        pRdrFile->off = -1;
        return KERR_GENERAL_FAILURE;
    }
    }

#else
# error "port me."
#endif

    pRdrFile->off = off + cb;
    return 0;
}


Generated by  Doxygen 1.6.0   Back to index