Changeset 131 for trunk/src/helpers/dosh.c
- Timestamp:
- Jan 9, 2002, 10:17:41 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r129 r131 1806 1806 // file ptr is at beginning 1807 1807 1808 #ifdef DEBUG_DOSOPEN 1808 1809 if (arc) 1809 1810 _Pmpf((__FUNCTION__ ": DosSetFilePtr/queryfilesize returned %d for %s", 1810 1811 arc, pcszFilename)); 1812 #endif 1811 1813 1812 1814 // store file size … … 1817 1819 pFile->pszFilename = strdup(pcszFilename); 1818 1820 } 1821 #ifdef DEBUG_DOSOPEN 1819 1822 else 1820 1823 _Pmpf((__FUNCTION__ ": DosOpen returned %d for %s", 1821 1824 arc, pcszFilename)); 1825 #endif 1822 1826 1823 1827 if (arc) … … 1891 1895 * cache. 1892 1896 * 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 * 1893 1908 *@@added V0.9.13 (2001-06-14) [umoeller] 1894 1909 *@@changed V0.9.16 (2001-12-18) [umoeller]: now with XFILE, and always using FILE_BEGIN … … 1896 1911 1897 1912 APIRET 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 1901 1917 { 1902 1918 APIRET arc; … … 1927 1943 *pcb = cb; 1928 1944 1945 #ifdef DEBUG_DOSOPEN 1929 1946 _Pmpf((__FUNCTION__ " %s: data is fully in cache", 1930 1947 pFile->pszFilename)); … … 1935 1952 _Pmpf((" so copied %d bytes from cache ofs %d", 1936 1953 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 1944 1955 } 1945 1956 else … … 1948 1959 // check how much it is... for small amounts, 1949 1960 // we load the cache first 1950 if (cb <= 4096 - 512) 1961 if ( (cb <= 4096 - 512) 1962 && (!(fl & DRFL_NOCACHE)) 1963 ) 1951 1964 { 1965 #ifdef DEBUG_DOSOPEN 1952 1966 _Pmpf((__FUNCTION__ " %s: filling cache anew", 1953 1967 pFile->pszFilename)); 1954 1968 _Pmpf((" caller wants %d bytes from %d", 1955 1969 cb, ulOffset)); 1970 #endif 1956 1971 1957 1972 // OK, then fix the offset to read from … … 1962 1977 pFile->cbCache = 4096; 1963 1978 1979 #ifdef DEBUG_DOSOPEN 1964 1980 _Pmpf((" getting %d bytes from %d", 1965 1981 pFile->cbCache, pFile->ulReadFrom)); 1982 #endif 1966 1983 1967 1984 // free old cache … … 1974 1991 else 1975 1992 { 1993 ULONG ulOfsInCache = 0; 1994 1976 1995 if (!(arc = DosSetFilePtr(pFile->hf, 1977 1996 (LONG)pFile->ulReadFrom, … … 1985 2004 { 1986 2005 // got data: 1987 ULONG ulOfsInCache; 1988 2006 #ifdef DEBUG_DOSOPEN 1989 2007 _Pmpf((" %d bytes read", ulDummy)); 2008 #endif 2009 1990 2010 pFile->cbCache = ulDummy; 1991 2011 1992 // c opy to caller2012 // check bounds 1993 2013 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 */ 2008 2023 } 2009 2024 } 2010 2025 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))) 2014 2045 } 2015 2046 else 2016 2047 { 2017 2048 // read uncached: 2049 #ifdef DEBUG_DOSOPEN 2018 2050 _Pmpf((" " __FUNCTION__ " %s: reading uncached", 2019 2051 pFile->pszFilename)); 2020 2052 _Pmpf((" caller wants %d bytes from %d", 2021 2053 cb, ulOffset)); 2054 #endif 2055 2022 2056 if (!(arc = DosSetFilePtr(pFile->hf, 2023 2057 (LONG)ulOffset, … … 2029 2063 cb, 2030 2064 &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 } 2032 2073 } 2033 2074 }
Note:
See TracChangeset
for help on using the changeset viewer.