Ignore:
Timestamp:
Jan 9, 2002, 10:17:41 PM (24 years ago)
Author:
umoeller
Message:

Coupla fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dosh.c

    r129 r131  
    18061806                    // file ptr is at beginning
    18071807
     1808                #ifdef DEBUG_DOSOPEN
    18081809                 if (arc)
    18091810                    _Pmpf((__FUNCTION__ ": DosSetFilePtr/queryfilesize returned %d for %s",
    18101811                                arc, pcszFilename));
     1812                #endif
    18111813
    18121814                // store file size
     
    18171819                pFile->pszFilename = strdup(pcszFilename);
    18181820            }
     1821            #ifdef DEBUG_DOSOPEN
    18191822            else
    18201823                 _Pmpf((__FUNCTION__ ": DosOpen returned %d for %s",
    18211824                             arc, pcszFilename));
     1825            #endif
    18221826
    18231827            if (arc)
     
    18911895 *      cache.
    18921896 *
     1897 *      fl may be any combination of the following:
     1898 *
     1899 *      --  DRFL_NOCACHE: do not fill the cache with
     1900 *          new data if the data is not in the cache
     1901 *          currently.
     1902 *
     1903 *      --  DRFL_FAILIFLESS: return ERROR_NO_DATA
     1904 *          if the data returned by DosRead is less
     1905 *          than what was specified. This might
     1906 *          simplify error handling.
     1907 *
    18931908 *@@added V0.9.13 (2001-06-14) [umoeller]
    18941909 *@@changed V0.9.16 (2001-12-18) [umoeller]: now with XFILE, and always using FILE_BEGIN
     
    18961911
    18971912APIRET doshReadAt(PXFILE pFile,
    1898                   ULONG ulOffset,    // in: offset to read from (from beginning of file)
    1899                   PULONG pcb,      // in: bytes to read, out: bytes read
    1900                   PBYTE pbData)    // out: read buffer (must be cb bytes)
     1913                  ULONG ulOffset,   // in: offset to read from (from beginning of file)
     1914                  PULONG pcb,       // in: bytes to read, out: bytes read
     1915                  PBYTE pbData,     // out: read buffer (must be cb bytes)
     1916                  ULONG fl)         // in: DRFL_* flags
    19011917{
    19021918    APIRET arc;
     
    19271943            *pcb = cb;
    19281944
     1945            #ifdef DEBUG_DOSOPEN
    19291946            _Pmpf((__FUNCTION__ " %s: data is fully in cache",
    19301947                        pFile->pszFilename));
     
    19351952            _Pmpf(("  so copied %d bytes from cache ofs %d",
    19361953                        cb, ulOfsInCache));
    1937 
    1938             // still, advance the file pointer because
    1939             // caller might run plain DosRead next
    1940             /* DosSetFilePtr(pFile->hf,
    1941                           (LONG)ulOffset + cb,
    1942                           FILE_BEGIN,
    1943                           &ulDummy); */
     1954            #endif
    19441955        }
    19451956        else
     
    19481959            // check how much it is... for small amounts,
    19491960            // we load the cache first
    1950             if (cb <= 4096 - 512)
     1961            if (    (cb <= 4096 - 512)
     1962                 && (!(fl & DRFL_NOCACHE))
     1963               )
    19511964            {
     1965                #ifdef DEBUG_DOSOPEN
    19521966                _Pmpf((__FUNCTION__ " %s: filling cache anew",
    19531967                        pFile->pszFilename));
    19541968                _Pmpf(("  caller wants %d bytes from %d",
    19551969                            cb, ulOffset));
     1970                #endif
    19561971
    19571972                // OK, then fix the offset to read from
     
    19621977                pFile->cbCache = 4096;
    19631978
     1979                #ifdef DEBUG_DOSOPEN
    19641980                _Pmpf(("  getting %d bytes from %d",
    19651981                            pFile->cbCache, pFile->ulReadFrom));
     1982                #endif
    19661983
    19671984                // free old cache
     
    19741991                else
    19751992                {
     1993                    ULONG ulOfsInCache = 0;
     1994
    19761995                    if (!(arc = DosSetFilePtr(pFile->hf,
    19771996                                              (LONG)pFile->ulReadFrom,
     
    19852004                        {
    19862005                            // got data:
    1987                             ULONG ulOfsInCache;
    1988 
     2006                            #ifdef DEBUG_DOSOPEN
    19892007                            _Pmpf(("        %d bytes read", ulDummy));
     2008                            #endif
     2009
    19902010                            pFile->cbCache = ulDummy;
    19912011
    1992                             // copy to caller
     2012                            // check bounds
    19932013                            ulOfsInCache = ulOffset - pFile->ulReadFrom;
    1994                             memcpy(pbData,
    1995                                    pFile->pbCache + ulOfsInCache,
    1996                                    cb);
    1997                             *pcb = cb;
    1998 
    1999                             _Pmpf(("  so copied %d bytes from cache ofs %d",
    2000                                         cb, ulOfsInCache));
    2001 
    2002                             // still, advance the file pointer because
    2003                             // caller might run plain DosRead next
    2004                             /* DosSetFilePtr(pFile->hf,
    2005                                           (LONG)ulOffset + cb,
    2006                                           FILE_BEGIN,
    2007                                           &ulDummy); */
     2014
     2015                            /*
     2016                            if (ulOfsInCache + cb > pFile->cbCache)
     2017                            {
     2018                                cb = pFile->cbCache - ulOfsInCache;
     2019                                if (fl & DRFL_FAILIFLESS)
     2020                                    arc = ERROR_NO_DATA;
     2021                            }
     2022                            */
    20082023                        }
    20092024                    }
    20102025
    2011                     if (arc)
    2012                         FREE(pFile->pbCache);
    2013                 }
     2026                    if (!arc)
     2027                    {
     2028                        // copy to caller
     2029                        memcpy(pbData,
     2030                               pFile->pbCache + ulOfsInCache,
     2031                               cb);
     2032                        *pcb = cb;
     2033
     2034                        #ifdef DEBUG_DOSOPEN
     2035                        _Pmpf(("  so copied %d bytes from cache ofs %d",
     2036                                    cb, ulOfsInCache));
     2037                        #endif
     2038                    }
     2039                    else
     2040                    {
     2041                        free(pFile->pbCache);
     2042                        pFile->pbCache = NULL;
     2043                    }
     2044                } // end else if (!(pFile->pbCache = (PBYTE)malloc(pFile->cbCache)))
    20142045            }
    20152046            else
    20162047            {
    20172048                // read uncached:
     2049                #ifdef DEBUG_DOSOPEN
    20182050                _Pmpf(("  " __FUNCTION__ " %s: reading uncached",
    20192051                            pFile->pszFilename));
    20202052                _Pmpf(("      caller wants %d bytes from %d",
    20212053                            cb, ulOffset));
     2054                #endif
     2055
    20222056                if (!(arc = DosSetFilePtr(pFile->hf,
    20232057                                          (LONG)ulOffset,
     
    20292063                                        cb,
    20302064                                        &ulDummy)))
    2031                         *pcb = ulDummy;     // bytes read
     2065                    {
     2066                        if (    (fl & DRFL_FAILIFLESS)
     2067                             && (ulDummy != cb)
     2068                           )
     2069                            arc = ERROR_NO_DATA;
     2070                        else
     2071                            *pcb = ulDummy;     // bytes read
     2072                    }
    20322073                }
    20332074            }
Note: See TracChangeset for help on using the changeset viewer.