Changeset 190 for trunk/src/helpers/dosh.c
- Timestamp:
- Jul 22, 2002, 10:08:02 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r169 r190 2854 2854 2855 2855 /* 2856 *@@ doshReadText: 2857 * reads all the contents of the given XFILE into 2858 * a newly allocated buffer. Handles Ctrl-Z properly. 2859 * 2860 * Implementation for doshLoadTextFile, but can 2861 * be called separately now. 2862 * 2863 *@@added V0.9.20 (2002-07-19) [umoeller] 2864 */ 2865 2866 APIRET doshReadText(PXFILE pFile, 2867 PSZ* ppszContent, // out: newly allocated buffer with file's content 2868 PULONG pcbRead) // out: size of that buffer including null byte (ptr can be NULL) 2869 { 2870 APIRET arc; 2871 PSZ pszContent; 2872 2873 if (!(pszContent = (PSZ)malloc(pFile->cbCurrent + 1))) 2874 arc = ERROR_NOT_ENOUGH_MEMORY; 2875 else 2876 { 2877 ULONG cbRead = 0; 2878 if (!(arc = DosRead(pFile->hf, 2879 pszContent, 2880 pFile->cbCurrent, 2881 &cbRead))) 2882 { 2883 if (cbRead != pFile->cbCurrent) 2884 arc = ERROR_NO_DATA; 2885 else 2886 { 2887 PSZ p; 2888 pszContent[cbRead] = '\0'; 2889 2890 // check if we have a ctrl-z (EOF) marker 2891 // this is present, for example, in config.sys 2892 // after install, and stupid E.EXE writes this 2893 // all the time when saving a file 2894 // V0.9.18 (2002-03-08) [umoeller] 2895 if (p = strchr(pszContent, '\26')) 2896 { 2897 *p = '\0'; 2898 cbRead = p - pszContent; 2899 } 2900 2901 *ppszContent = pszContent; 2902 if (pcbRead) 2903 *pcbRead = cbRead + 1; 2904 } 2905 } 2906 2907 if (arc) 2908 free(pszContent); 2909 } 2910 2911 return arc; 2912 } 2913 2914 /* 2856 2915 *@@ doshLoadTextFile: 2857 2916 * reads a text file from disk, allocates memory … … 2892 2951 &pFile))) 2893 2952 { 2894 PSZ pszContent; 2895 if (!(pszContent = (PSZ)malloc(cbFile + 1))) 2896 arc = ERROR_NOT_ENOUGH_MEMORY; 2897 else 2898 { 2899 ULONG cbRead = 0; 2900 if (!(arc = DosRead(pFile->hf, 2901 pszContent, 2902 cbFile, 2903 &cbRead))) 2904 { 2905 if (cbRead != cbFile) 2906 arc = ERROR_NO_DATA; 2907 else 2908 { 2909 PSZ p; 2910 pszContent[cbRead] = '\0'; 2911 2912 // check if we have a ctrl-z (EOF) marker 2913 // this is present, for example, in config.sys 2914 // after install 2915 // V0.9.18 (2002-03-08) [umoeller] 2916 if (p = strchr(pszContent, '\26')) 2917 { 2918 *p = '\0'; 2919 cbRead = p - pszContent; 2920 } 2921 2922 *ppszContent = pszContent; 2923 if (pcbRead) 2924 *pcbRead = cbRead + 1; 2925 } 2926 } 2927 2928 if (arc) 2929 free(pszContent); 2930 } 2931 2953 doshReadText(pFile, 2954 ppszContent, 2955 pcbRead); 2932 2956 doshClose(&pFile); 2933 2957 }
Note:
See TracChangeset
for help on using the changeset viewer.