gfx/skia/trunk/src/ports/SkOSFile_posix.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /*
     2  * Copyright 2013 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #include "SkOSFile.h"
    10 #include "SkTFitsIn.h"
    12 #include <stdio.h>
    13 #include <sys/mman.h>
    14 #include <sys/stat.h>
    15 #include <sys/types.h>
    17 typedef struct {
    18     dev_t dev;
    19     ino_t ino;
    20 } SkFILEID;
    22 static bool sk_ino(SkFILE* a, SkFILEID* id) {
    23     int fd = fileno((FILE*)a);
    24     if (fd < 0) {
    25         return 0;
    26     }
    27     struct stat status;
    28     if (0 != fstat(fd, &status)) {
    29         return 0;
    30     }
    31     id->dev = status.st_dev;
    32     id->ino = status.st_ino;
    33     return true;
    34 }
    36 bool sk_fidentical(SkFILE* a, SkFILE* b) {
    37     SkFILEID aID, bID;
    38     return sk_ino(a, &aID) && sk_ino(b, &bID)
    39            && aID.ino == bID.ino
    40            && aID.dev == bID.dev;
    41 }
    43 void sk_fmunmap(const void* addr, size_t length) {
    44     munmap(const_cast<void*>(addr), length);
    45 }
    47 void* sk_fdmmap(int fd, size_t* size) {
    48     struct stat status;
    49     if (0 != fstat(fd, &status)) {
    50         return NULL;
    51     }
    52     if (!S_ISREG(status.st_mode)) {
    53         return NULL;
    54     }
    55     if (!SkTFitsIn<size_t>(status.st_size)) {
    56         return NULL;
    57     }
    58     size_t fileSize = static_cast<size_t>(status.st_size);
    60     void* addr = mmap(NULL, fileSize, PROT_READ, MAP_PRIVATE, fd, 0);
    61     if (MAP_FAILED == addr) {
    62         return NULL;
    63     }
    65     *size = fileSize;
    66     return addr;
    67 }
    69 int sk_fileno(SkFILE* f) {
    70     return fileno((FILE*)f);
    71 }
    73 void* sk_fmmap(SkFILE* f, size_t* size) {
    74     int fd = sk_fileno(f);
    75     if (fd < 0) {
    76         return NULL;
    77     }
    79     return sk_fdmmap(fd, size);
    80 }

mercurial