toolkit/mozapps/update/updater/win_dirent.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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "win_dirent.h"
michael@0 8 #include <errno.h>
michael@0 9 #include <string.h>
michael@0 10
michael@0 11 // This file implements the minimum set of dirent APIs used by updater.cpp on
michael@0 12 // Windows. If updater.cpp is modified to use more of this API, we need to
michael@0 13 // implement those parts here too.
michael@0 14
michael@0 15 static dirent gDirEnt;
michael@0 16
michael@0 17 DIR::DIR(const WCHAR* path)
michael@0 18 : findHandle(INVALID_HANDLE_VALUE)
michael@0 19 {
michael@0 20 memset(name, 0, sizeof(name));
michael@0 21 wcsncpy(name, path, sizeof(name)/sizeof(name[0]));
michael@0 22 wcsncat(name, L"\\*", sizeof(name)/sizeof(name[0]) - wcslen(name) - 1);
michael@0 23 }
michael@0 24
michael@0 25 DIR::~DIR()
michael@0 26 {
michael@0 27 if (findHandle != INVALID_HANDLE_VALUE) {
michael@0 28 FindClose(findHandle);
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 dirent::dirent()
michael@0 33 {
michael@0 34 d_name[0] = L'\0';
michael@0 35 }
michael@0 36
michael@0 37 DIR*
michael@0 38 opendir(const WCHAR* path)
michael@0 39 {
michael@0 40 return new DIR(path);
michael@0 41 }
michael@0 42
michael@0 43 int
michael@0 44 closedir(DIR* dir)
michael@0 45 {
michael@0 46 delete dir;
michael@0 47 return 0;
michael@0 48 }
michael@0 49
michael@0 50 dirent* readdir(DIR* dir)
michael@0 51 {
michael@0 52 WIN32_FIND_DATAW data;
michael@0 53 if (dir->findHandle != INVALID_HANDLE_VALUE) {
michael@0 54 BOOL result = FindNextFileW(dir->findHandle, &data);
michael@0 55 if (!result) {
michael@0 56 if (GetLastError() != ERROR_FILE_NOT_FOUND) {
michael@0 57 errno = ENOENT;
michael@0 58 }
michael@0 59 return 0;
michael@0 60 }
michael@0 61 } else {
michael@0 62 // Reading the first directory entry
michael@0 63 dir->findHandle = FindFirstFileW(dir->name, &data);
michael@0 64 if (dir->findHandle == INVALID_HANDLE_VALUE) {
michael@0 65 if (GetLastError() == ERROR_FILE_NOT_FOUND) {
michael@0 66 errno = ENOENT;
michael@0 67 } else {
michael@0 68 errno = EBADF;
michael@0 69 }
michael@0 70 return 0;
michael@0 71 }
michael@0 72 }
michael@0 73 memset(gDirEnt.d_name, 0, sizeof(gDirEnt.d_name));
michael@0 74 wcsncpy(gDirEnt.d_name, data.cFileName,
michael@0 75 sizeof(gDirEnt.d_name)/sizeof(gDirEnt.d_name[0]));
michael@0 76 return &gDirEnt;
michael@0 77 }
michael@0 78

mercurial