00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _WIN32
00015
00016 #include "define.h"
00017
00018 char * fileTimeToAscii (const FILETIME *filetime) {
00019 time_t t1;
00020
00021 t1 = fileTimeToUnixTime(filetime, NULL);
00022 return ctime(&t1);
00023 }
00024
00025 struct tm * fileTimeToStructTM (const FILETIME *filetime) {
00026 time_t t1;
00027 t1 = fileTimeToUnixTime(filetime, NULL);
00028 return gmtime(&t1);
00029 }
00030
00031
00032
00033
00034
00035
00036
00037
00038 time_t fileTimeToUnixTime( const FILETIME *filetime, DWORD *remainder )
00039 {
00040
00041 #if USE_LONG_LONG
00042
00043 long long int t = filetime->dwHighDateTime;
00044 t <<= 32;
00045 t += (UINT32)filetime->dwLowDateTime;
00046 t -= 116444736000000000LL;
00047 if (t < 0)
00048 {
00049 if (remainder) *remainder = 9999999 - (-t - 1) % 10000000;
00050 return -1 - ((-t - 1) / 10000000);
00051 }
00052 else
00053 {
00054 if (remainder) *remainder = t % 10000000;
00055 return t / 10000000;
00056 }
00057
00058 #else
00059
00060 UINT32 a0;
00061 UINT32 a1;
00062 UINT32 a2;
00063 UINT32 r;
00064 unsigned int carry;
00065 int negative;
00066
00067
00068 a2 = (UINT32)filetime->dwHighDateTime;
00069 a1 = ((UINT32)filetime->dwLowDateTime ) >> 16;
00070 a0 = ((UINT32)filetime->dwLowDateTime ) & 0xffff;
00071
00072
00073 if (a0 >= 32768 ) a0 -= 32768 , carry = 0;
00074 else a0 += (1 << 16) - 32768 , carry = 1;
00075
00076 if (a1 >= 54590 + carry) a1 -= 54590 + carry, carry = 0;
00077 else a1 += (1 << 16) - 54590 - carry, carry = 1;
00078
00079 a2 -= 27111902 + carry;
00080
00081
00082 negative = (a2 >= ((UINT32)1) << 31);
00083 if (negative)
00084 {
00085
00086 a0 = 0xffff - a0;
00087 a1 = 0xffff - a1;
00088 a2 = ~a2;
00089 }
00090
00091
00092
00093 a1 += (a2 % 10000) << 16;
00094 a2 /= 10000;
00095 a0 += (a1 % 10000) << 16;
00096 a1 /= 10000;
00097 r = a0 % 10000;
00098 a0 /= 10000;
00099
00100 a1 += (a2 % 1000) << 16;
00101 a2 /= 1000;
00102 a0 += (a1 % 1000) << 16;
00103 a1 /= 1000;
00104 r += (a0 % 1000) * 10000;
00105 a0 /= 1000;
00106
00107
00108 if (negative)
00109 {
00110
00111 a0 = 0xffff - a0;
00112 a1 = 0xffff - a1;
00113 a2 = ~a2;
00114
00115 r = 9999999 - r;
00116 }
00117
00118 if (remainder) *remainder = r;
00119
00120
00121
00122 return ((((time_t)a2) << 16) << 16) + (a1 << 16) + a0;
00123 #endif
00124 }
00125
00126 #endif