michael@0: // michael@0: // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #ifndef _MMAP_INCLUDED_ michael@0: #define _MMAP_INCLUDED_ michael@0: michael@0: // michael@0: // Encapsulate memory mapped files michael@0: // michael@0: michael@0: class TMMap { michael@0: public: michael@0: TMMap(const char* fileName) : michael@0: fSize(-1), // -1 is the error value returned by GetFileSize() michael@0: fp(NULL), michael@0: fBuff(0) // 0 is the error value returned by MapViewOfFile() michael@0: { michael@0: if ((fp = fopen(fileName, "r")) == NULL) michael@0: return; michael@0: char c = getc(fp); michael@0: fSize = 0; michael@0: while (c != EOF) { michael@0: fSize++; michael@0: c = getc(fp); michael@0: } michael@0: if (c == EOF) michael@0: fSize++; michael@0: rewind(fp); michael@0: fBuff = (char*)malloc(sizeof(char) * fSize); michael@0: int count = 0; michael@0: c = getc(fp); michael@0: while (c != EOF) { michael@0: fBuff[count++] = c; michael@0: c = getc(fp); michael@0: } michael@0: fBuff[count++] = c; michael@0: } michael@0: michael@0: char* getData() { return fBuff; } michael@0: int getSize() { return fSize; } michael@0: michael@0: ~TMMap() { michael@0: if (fp != NULL) michael@0: fclose(fp); michael@0: } michael@0: michael@0: private: michael@0: int fSize; // size of file to map in michael@0: FILE *fp; michael@0: char* fBuff; // the actual data; michael@0: }; michael@0: michael@0: #endif // _MMAP_INCLUDED_