Changeset 5531 for trunk/tools/common/kFileFormatBase.cpp
- Timestamp:
- Apr 17, 2001, 2:26:28 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFileFormatBase.cpp
r5053 r5531 1 /* $Id: kFileFormatBase.cpp,v 1. 3 2001-02-02 08:45:41 bird Exp $1 /* $Id: kFileFormatBase.cpp,v 1.4 2001-04-17 00:26:11 bird Exp $ 2 2 * 3 3 * kFileFormatBase - Base class for kFile<format> classes. … … 21 21 22 22 #include "kFile.h" 23 #include "kInterfaces.h" 23 24 #include "kFileFormatBase.h" 24 25 25 26 27 28 /**29 * Creates a memory buffer for a binary file.30 * @returns Pointer to file memoryblock. NULL on error.31 * @param pszFilename Pointer to filename string.32 * @remark This function is the one using most of the execution33 * time (DosRead + DosOpen) - about 70% of the execution time!34 */35 void *kFileFormatBase::readfile(const char *pszFilename)36 {37 void *pvFile = NULL;38 FILE *phFile;39 40 phFile = fopen(pszFilename, "rb");41 if (phFile != NULL)42 {43 long int cbFile;44 45 if (ftell(phFile) < 046 ||47 fseek(phFile, 0, SEEK_END) != 048 ||49 (cbFile = ftell(phFile)) < 050 ||51 fseek(phFile, 0, SEEK_SET) != 052 )53 cbFile = -1;54 55 if (cbFile > 0)56 {57 pvFile = malloc((size_t)cbFile + 1);58 if (pvFile != NULL)59 {60 memset(pvFile, 0, (size_t)cbFile + 1);61 if (fread(pvFile, 1, (size_t)cbFile, phFile) == 0)62 { /* failed! */63 free(pvFile);64 pvFile = NULL;65 }66 }67 else68 fprintf(stderr, "warning/error: failed to open file %s\n", pszFilename);69 }70 fclose(phFile);71 }72 return pvFile;73 }74 26 75 27 /**
Note:
See TracChangeset
for help on using the changeset viewer.