Changeset 4129 for trunk/tools/common/kFile.cpp
- Timestamp:
- Aug 31, 2000, 5:00:13 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFile.cpp
r3629 r4129 1 /* $Id: kFile.cpp,v 1. 3 2000-05-29 19:45:57bird Exp $1 /* $Id: kFile.cpp,v 1.4 2000-08-31 03:00:12 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 39 39 if (!fStatusClean) 40 40 { 41 rc = (int)DosQueryFileInfo(hFile, FIL_QUERYEASIZE, &filestatus, sizeof(filestatus));41 rc = DosQueryFileInfo(hFile, FIL_QUERYEASIZE, &filestatus, sizeof(filestatus)); 42 42 fStatusClean = (rc == NO_ERROR); 43 43 if (!fStatusClean && fThrowErrors) 44 throw ( rc);44 throw ((int)rc); 45 45 } 46 46 else … … 64 64 { 65 65 ULONG off; 66 rc = (int)DosSetFilePtr(hFile, offVirtual, FILE_BEGIN, &off);66 rc = DosSetFilePtr(hFile, offVirtual, FILE_BEGIN, &off); 67 67 if (rc != NO_ERROR || off != offVirtual) 68 68 { 69 69 if (fThrowErrors) 70 throw ( rc);70 throw ((int)rc); 71 71 return FALSE; 72 72 } … … 86 86 * FALSE: Open the file readwrite appending 87 87 * existing files. 88 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)88 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 89 89 */ 90 90 kFile::kFile(const char *pszFilename, BOOL fReadOnly/*=TRUE*/) … … 93 93 fThrowErrors(FALSE), 94 94 offVirtual(0), 95 offReal(0) 95 offReal(0), 96 pszFilename(NULL) 96 97 { 97 98 ULONG fulOpenFlags; … … 113 114 } 114 115 115 rc = (int)DosOpen((PCSZ)pszFilename, &hFile, &ulAction, 0, FILE_NORMAL,116 116 rc = DosOpen((PCSZ)pszFilename, &hFile, &ulAction, 0, FILE_NORMAL, 117 fulOpenFlags, fulOpenMode, NULL); 117 118 if (rc != NO_ERROR) 118 throw ( rc);119 throw ((int)rc); 119 120 120 121 if (!refreshFileStatus()) 121 throw (rc); 122 throw ((int)rc); 123 124 char szFullName[CCHMAXPATH]; 125 if (DosQueryPathInfo(pszFilename, FIL_QUERYFULLNAME, szFullName, sizeof(szFullName))) 126 strcpy(szFullName, pszFilename); 127 this->pszFilename = strdup(szFullName); 128 if (this->pszFilename == NULL) 129 throw (ERROR_NOT_ENOUGH_MEMORY); 122 130 } 123 131 … … 143 151 { 144 152 ULONG cbRead; 145 rc = (int)DosRead(hFile, pvBuffer, cbBuffer, &cbRead);153 rc = DosRead(hFile, pvBuffer, cbBuffer, &cbRead); 146 154 if (rc == NO_ERROR) 147 155 { … … 152 160 153 161 if (fThrowErrors) 154 throw ( rc);162 throw ((int)rc); 155 163 return FALSE; 156 164 } … … 171 179 172 180 /** 181 * Reads the entire file into a single memory block. 182 * (The memory block has a '\0' at the end just in case you 183 * are using it as a long string.) 184 * @returns Pointer to file in memory. 185 */ 186 void * kFile::readFile() throw(int) 187 { 188 void *pv; 189 190 /* allocate memory for the file */ 191 pv = calloc((size_t)this->getSize() + 1, 1); 192 if (pv == NULL) 193 { 194 if (fThrowErrors) 195 throw(ERROR_NOT_ENOUGH_MEMORY); 196 return NULL; 197 } 198 199 /* go the start of the file and read it. */ 200 if (start() && read(pv, this->getSize())) 201 return pv; // successfull exit! 202 203 /* we failed, cleanup and return NULL */ 204 free(pv); 205 return NULL; 206 } 207 208 209 /** 173 210 * Writes <cbBuffer> bytes to the file at the current file position. 174 211 * @returns success indicator. (TRUE/FALSE) … … 186 223 ULONG cbWrote; 187 224 188 rc = (int)DosWrite(hFile, pvBuffer, cbBuffer, &cbWrote);225 rc = DosWrite(hFile, pvBuffer, cbBuffer, &cbWrote); 189 226 if (rc == NO_ERROR) 190 227 { … … 197 234 198 235 if (fThrowErrors) 199 throw (rc);236 throw ((int)rc); 200 237 return FALSE; 201 238 } … … 253 290 free(pszBuffer); 254 291 255 return getPos() - offStart; 256 } 257 292 return (int)(getPos() - offStart); 293 } 294 295 296 /** 297 * Sets the filesize. 298 * @returns Success indicator. 299 * @param cbFile New filesize. 300 * Defaults to 0xffffffff, which results in 301 * cutting the file at the current position. 302 */ 303 BOOL kFile::setSize(unsigned long cbFile/*= ~0UL*/) 304 { 305 if (cbFile == ~0UL) 306 cbFile = offVirtual; 307 rc = DosSetFileSize(hFile, cbFile); 308 if (rc != NO_ERROR && fThrowErrors) 309 throw ((int)rc); 310 311 return rc == NO_ERROR; 312 } 258 313 259 314 … … 280 335 281 336 if (fThrowErrors) 282 throw (rc);337 throw ((int)rc); 283 338 return FALSE; 284 339 } … … 306 361 } 307 362 if (fThrowErrors) 308 throw (rc);363 throw ((int)rc); 309 364 return FALSE; 310 365 }
Note:
See TracChangeset
for help on using the changeset viewer.