1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/MMap.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +#ifndef _MMAP_INCLUDED_ 1.11 +#define _MMAP_INCLUDED_ 1.12 + 1.13 +// 1.14 +// Encapsulate memory mapped files 1.15 +// 1.16 + 1.17 +class TMMap { 1.18 +public: 1.19 + TMMap(const char* fileName) : 1.20 + fSize(-1), // -1 is the error value returned by GetFileSize() 1.21 + fp(NULL), 1.22 + fBuff(0) // 0 is the error value returned by MapViewOfFile() 1.23 + { 1.24 + if ((fp = fopen(fileName, "r")) == NULL) 1.25 + return; 1.26 + char c = getc(fp); 1.27 + fSize = 0; 1.28 + while (c != EOF) { 1.29 + fSize++; 1.30 + c = getc(fp); 1.31 + } 1.32 + if (c == EOF) 1.33 + fSize++; 1.34 + rewind(fp); 1.35 + fBuff = (char*)malloc(sizeof(char) * fSize); 1.36 + int count = 0; 1.37 + c = getc(fp); 1.38 + while (c != EOF) { 1.39 + fBuff[count++] = c; 1.40 + c = getc(fp); 1.41 + } 1.42 + fBuff[count++] = c; 1.43 + } 1.44 + 1.45 + char* getData() { return fBuff; } 1.46 + int getSize() { return fSize; } 1.47 + 1.48 + ~TMMap() { 1.49 + if (fp != NULL) 1.50 + fclose(fp); 1.51 + } 1.52 + 1.53 +private: 1.54 + int fSize; // size of file to map in 1.55 + FILE *fp; 1.56 + char* fBuff; // the actual data; 1.57 +}; 1.58 + 1.59 +#endif // _MMAP_INCLUDED_