gfx/angle/src/compiler/MMap.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 //
     2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
     3 // Use of this source code is governed by a BSD-style license that can be
     4 // found in the LICENSE file.
     5 //
     7 #ifndef _MMAP_INCLUDED_
     8 #define _MMAP_INCLUDED_
    10 //
    11 // Encapsulate memory mapped files
    12 //
    14 class TMMap {
    15 public:
    16     TMMap(const char* fileName) : 
    17         fSize(-1), // -1 is the error value returned by GetFileSize()
    18         fp(NULL),
    19         fBuff(0)   // 0 is the error value returned by MapViewOfFile()
    20     {
    21         if ((fp = fopen(fileName, "r")) == NULL)
    22             return;
    23         char c = getc(fp);
    24         fSize = 0;
    25         while (c != EOF) {
    26             fSize++;
    27             c = getc(fp);
    28         }
    29         if (c == EOF)
    30             fSize++;
    31         rewind(fp);
    32         fBuff = (char*)malloc(sizeof(char) * fSize);
    33         int count = 0;
    34         c = getc(fp);
    35         while (c != EOF) {
    36             fBuff[count++] = c;
    37             c = getc(fp);
    38         }
    39         fBuff[count++] = c;
    40     }
    42     char* getData() { return fBuff; }
    43     int   getSize() { return fSize; }
    45     ~TMMap() {
    46         if (fp != NULL)
    47             fclose(fp);
    48     }
    50 private:
    51     int             fSize;      // size of file to map in
    52     FILE *fp;
    53     char*           fBuff;      // the actual data;
    54 };
    56 #endif // _MMAP_INCLUDED_

mercurial