other-licenses/7zstub/src/Windows/Time.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 // Windows/Time.h
     3 #ifndef __WINDOWS_TIME_H
     4 #define __WINDOWS_TIME_H
     6 #include "Common/Types.h"
     7 #include "Windows/Defs.h"
     9 namespace NWindows {
    10 namespace NTime {
    12 inline bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)
    13 {
    14   return BOOLToBool(::DosDateTimeToFileTime(UInt16(dosTime >> 16), 
    15       UInt16(dosTime & 0xFFFF), &fileTime));
    16 }
    18 const UInt32 kHighDosTime = 0xFF9FBF7D;
    19 const UInt32 kLowDosTime = 0x210000;
    21 inline bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)
    22 {
    23   WORD datePart, timePart;
    24   if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))
    25   {
    26     if (fileTime.dwHighDateTime >= 0x01C00000) // 2000
    27       dosTime = kHighDosTime;
    28     else
    29       dosTime = kLowDosTime;
    30     return false;
    31   }
    32   dosTime = (((UInt32)datePart) << 16) + timePart;
    33   return true;
    34 }
    36 const UInt32 kNumTimeQuantumsInSecond = 10000000;
    37 const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;
    39 inline void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)
    40 {
    41   UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;
    42   fileTime.dwLowDateTime = (DWORD)v;
    43   fileTime.dwHighDateTime = (DWORD)(v >> 32);
    44 }
    46 inline bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)
    47 {
    48   UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
    49   if (winTime < kUnixTimeStartValue)
    50   {
    51     unixTime = 0;
    52     return false;
    53   }
    54   winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;
    55   if (winTime > 0xFFFFFFFF)
    56   {
    57     unixTime = 0xFFFFFFFF;
    58     return false;
    59   }
    60   unixTime = (UInt32)winTime;
    61   return true;
    62 }
    64 }}
    66 #endif

mercurial