Changeset 127 for trunk/src/helpers/dosh.c
- Timestamp:
- Jan 5, 2002, 8:11:10 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r126 r127 1640 1640 */ 1641 1641 1642 /* 1642 1643 APIRET doshOpenExisting(PCSZ pcszFilename, // in: file name 1643 1644 ULONG ulOpenFlags, // in: open flags … … 1654 1655 NULL)); // EAs 1655 1656 } 1656 1657 /* 1658 *@@ doshWriteAt: 1659 * writes cb bytes (pointed to by pbData) to the 1660 * position specified by ulMethod and lOffset into 1661 * the file specified by hf. 1662 * 1663 * If ulMethod is FILE_BEGIN, lOffset specifies the 1664 * offset from the beginning of the file. With 1665 * FILE_CURRENT, lOffset is considered from the 1666 * current file pointer, and with FILE_END, it is 1667 * considered from the end of the file. 1668 * 1669 *@@added V0.9.13 (2001-06-14) [umoeller] 1670 */ 1671 1672 APIRET doshWriteAt(HFILE hf, // in: OS/2 file handle 1673 LONG lOffset, // in: offset to write at (depends on ulMethod) 1674 ULONG ulMethod, // in: one of FILE_BEGIN, FILE_CURRENT, FILE_END 1675 ULONG cb, // in: bytes to write 1676 PBYTE pbData) // in: ptr to bytes to write (must be cb bytes) 1677 { 1678 APIRET arc; 1679 ULONG ulDummy; 1680 if (!(arc = DosSetFilePtr(hf, 1681 lOffset, 1682 ulMethod, 1683 &ulDummy))) 1684 arc = DosWrite(hf, 1685 pbData, 1686 cb, 1687 &ulDummy); 1688 1689 return (arc); 1690 } 1691 1692 /* 1693 *@@ doshReadAt: 1694 * reads cb bytes from the position specified by 1695 * ulMethod and lOffset into the buffer pointed to 1696 * by pbData, which should be cb bytes in size. 1697 * 1698 * Use lOffset and ulMethod as with doshWriteAt. 1699 * 1700 *@@added V0.9.13 (2001-06-14) [umoeller] 1701 */ 1702 1703 APIRET doshReadAt(HFILE hf, // in: OS/2 file handle 1704 LONG lOffset, // in: offset to write at (depends on ulMethod) 1705 ULONG ulMethod, // in: one of FILE_BEGIN, FILE_CURRENT, FILE_END 1706 PULONG pcb, // in: bytes to read, out: bytes read 1707 PBYTE pbData) // out: read buffer (must be cb bytes) 1708 { 1709 APIRET arc; 1710 ULONG cb = *pcb; 1711 ULONG ulDummy; 1712 1713 *pcb = 0; 1714 1715 if (!(arc = DosSetFilePtr(hf, 1716 lOffset, 1717 ulMethod, 1718 &ulDummy))) 1719 { 1720 if (!(arc = DosRead(hf, 1721 pbData, 1722 cb, 1723 &ulDummy))) 1724 *pcb = ulDummy; // bytes read 1725 } 1726 1727 return (arc); 1728 } 1657 */ 1729 1658 1730 1659 /* … … 1741 1670 + +-------------------------+------+------------+-----------+ 1742 1671 + | XOPEN_READ_EXISTING | read | opens | fails | 1672 + | | | fptr = 0 | | 1673 + +-------------------------+------+------------+-----------+ 1674 + | XOPEN_READWRITE_EXISTING r/w | opens | fails | 1743 1675 + | | | fptr = 0 | | 1744 1676 + +-------------------------+------+------------+-----------+ … … 1802 1734 fsOpenMode |= OPEN_SHARE_DENYWRITE 1803 1735 | OPEN_ACCESS_READONLY; 1804 // _Pmpf((__FUNCTION__ ": opening XOPEN_READ_EXISTING"));1805 1736 1806 1737 // run this first, because if the file doesn't … … 1808 1739 // which isn't that meaningful 1809 1740 // V0.9.16 (2001-12-08) [umoeller] 1741 arc = doshQueryPathSize(pcszFilename, 1742 pcbFile); 1743 break; 1744 1745 case XOPEN_READWRITE_EXISTING: 1746 fsOpenFlags = OPEN_ACTION_FAIL_IF_NEW 1747 | OPEN_ACTION_OPEN_IF_EXISTS; 1748 fsOpenMode |= OPEN_SHARE_DENYWRITE 1749 | OPEN_ACCESS_READWRITE; 1750 1810 1751 arc = doshQueryPathSize(pcszFilename, 1811 1752 pcbFile); … … 1928 1869 1929 1870 /* 1871 *@@ doshReadAt: 1872 * reads cb bytes from the position specified by 1873 * lOffset into the buffer pointed to by pbData, 1874 * which should be cb bytes in size. 1875 * 1876 * Note that lOffset is always considered to 1877 * be from the beginning of the file (FILE_BEGIN 1878 * method). 1879 * 1880 *@@added V0.9.13 (2001-06-14) [umoeller] 1881 *@@changed V0.9.16 (2001-12-18) [umoeller]: now with XFILE, and always using FILE_BEGIN 1882 */ 1883 1884 APIRET doshReadAt(PXFILE pFile, 1885 ULONG ulOffset, // in: offset to read from (from beginning of file) 1886 PULONG pcb, // in: bytes to read, out: bytes read 1887 PBYTE pbData) // out: read buffer (must be cb bytes) 1888 { 1889 APIRET arc; 1890 ULONG cb = *pcb; 1891 ULONG ulDummy; 1892 1893 if (!(arc = doshLockFile(pFile))) // this checks for pFile 1894 { 1895 *pcb = 0; 1896 1897 if (!(arc = DosSetFilePtr(pFile->hf, 1898 (LONG)ulOffset, 1899 FILE_BEGIN, 1900 &ulDummy))) 1901 { 1902 if (!(arc = DosRead(pFile->hf, 1903 pbData, 1904 cb, 1905 &ulDummy))) 1906 *pcb = ulDummy; // bytes read 1907 } 1908 1909 doshUnlockFile(pFile); 1910 } 1911 1912 return (arc); 1913 } 1914 1915 /* 1930 1916 *@@ doshWrite: 1931 1917 * writes the specified data to the file. … … 1937 1923 * writing. 1938 1924 * 1925 * Note that this expects that the file 1926 * pointer is at the end of the file, or 1927 * you will get garbage. 1928 * 1939 1929 *@@added V0.9.16 (2001-10-19) [umoeller] 1940 1930 *@@changed V0.9.16 (2001-12-02) [umoeller]: added XOPEN_BINARY \r\n support … … 1943 1933 1944 1934 APIRET doshWrite(PXFILE pFile, 1945 PCSZ pcsz,1946 ULONG cb)1935 ULONG cb, 1936 PCSZ pbData) 1947 1937 { 1948 1938 APIRET arc = NO_ERROR; 1949 if ((!pFile) || (!p csz))1939 if ((!pFile) || (!pbData)) 1950 1940 arc = ERROR_INVALID_PARAMETER; 1951 1941 else 1952 1942 { 1953 1943 if (!cb) 1954 cb = strlen(p csz);1944 cb = strlen(pbData); 1955 1945 1956 1946 if (!cb) … … 1967 1957 // count all \n first 1968 1958 ULONG cNewLines = 0; 1969 PCSZ pSource = p csz;1959 PCSZ pSource = pbData; 1970 1960 ULONG ul; 1971 1961 for (ul = 0; … … 1987 1977 { 1988 1978 PSZ pTarget = pszNew; 1989 pSource = p csz;1979 pSource = pbData; 1990 1980 for (ul = 0; 1991 1981 ul < cb; … … 2010 2000 (pszNew) 2011 2001 ? pszNew 2012 : (PSZ)p csz,2002 : (PSZ)pbData, 2013 2003 cb, 2014 2004 &cbWritten))) … … 2021 2011 free(pszNew); 2022 2012 } 2013 } 2014 2015 return (arc); 2016 } 2017 2018 /* 2019 *@@ doshWriteAt: 2020 * writes cb bytes (pointed to by pbData) to the 2021 * specified file at the position lOffset (from 2022 * the beginning of the file). 2023 * 2024 *@@added V0.9.13 (2001-06-14) [umoeller] 2025 */ 2026 2027 APIRET doshWriteAt(PXFILE pFile, 2028 ULONG ulOffset, // in: offset to write at 2029 ULONG cb, // in: bytes to write 2030 PCSZ pbData) // in: ptr to bytes to write (must be cb bytes) 2031 { 2032 APIRET arc; 2033 if (!(arc = doshLockFile(pFile))) // this checks for pFile 2034 { 2035 ULONG cbWritten; 2036 if (!(arc = DosSetFilePtr(pFile->hf, 2037 (LONG)ulOffset, 2038 FILE_BEGIN, 2039 &cbWritten))) 2040 { 2041 if (!(arc = DosWrite(pFile->hf, 2042 (PSZ)pbData, 2043 cb, 2044 &cbWritten))) 2045 { 2046 if (ulOffset + cbWritten > pFile->cbCurrent) 2047 pFile->cbCurrent = ulOffset + cbWritten; 2048 } 2049 } 2050 2051 doshUnlockFile(pFile); 2023 2052 } 2024 2053 … … 2059 2088 { 2060 2089 if (!(arc = doshWrite(pFile, 2061 szTemp,2062 ulLength)))2090 ulLength, 2091 szTemp))) 2063 2092 { 2064 2093 va_list arg_ptr; … … 2073 2102 2074 2103 arc = doshWrite(pFile, 2075 (PCSZ)szTemp,2076 ulLength);2104 ulLength, 2105 szTemp); 2077 2106 } 2078 2107 }
Note:
See TracChangeset
for help on using the changeset viewer.