From 202e1f9bf4739c096d47d9c6d271319245882684 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Wed, 1 Jan 2025 14:26:00 +0100 Subject: [PATCH 1/4] corec: remove unused TimePackToRel() We can use the structure values directly. --- corec/corec/helpers/date/date.h | 1 - corec/corec/helpers/date/date_libc.c | 43 ---------------------- corec/corec/helpers/date/date_win32.c | 52 --------------------------- 3 files changed, 96 deletions(-) diff --git a/corec/corec/helpers/date/date.h b/corec/corec/helpers/date/date.h index 79b2bf17..a28e9002 100644 --- a/corec/corec/helpers/date/date.h +++ b/corec/corec/helpers/date/date.h @@ -41,7 +41,6 @@ typedef struct datepack_t } datepack_t; DATE_DLL datetime_t GetTimeDate(void); // UTC in s (reference is 1st January 2001 00:00:00.000 UTC, use a helper to get the localized string value) -DATE_DLL datetime_t TimePackToRel(const datepack_t *tp, bool_t FromLocal); DATE_DLL bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t ToLocal); #ifdef __cplusplus diff --git a/corec/corec/helpers/date/date_libc.c b/corec/corec/helpers/date/date_libc.c index 27bb1e51..c4a4328a 100644 --- a/corec/corec/helpers/date/date_libc.c +++ b/corec/corec/helpers/date/date_libc.c @@ -27,54 +27,11 @@ datetime_t LinuxToDateTime(time_t t) return (datetime_t)t; } -static time_t DateTimeTZOffset(time_t t) -{ - time_t offset = 0; - struct tm *tmp = NULL; - tmp = localtime(&t); - if (tmp) { - offset = mktime(tmp); - tmp = gmtime(&t); - if (tmp) { - offset -= mktime(tmp); - } else { - offset = 0; - } - } - return offset; -} - datetime_t GetTimeDate(void) { return LinuxToDateTime(time(NULL)); } -datetime_t TimePackToRel(const datepack_t *tp, bool_t Local) -{ - struct tm date; - time_t ot = 0; - - if (!tp) - return INVALID_DATETIME_T; - - date.tm_sec = (int)tp->Second; - date.tm_min = (int)tp->Minute; - date.tm_hour = (int)tp->Hour; - date.tm_mday = (int)tp->Day; - date.tm_mon = (int)tp->Month - 1; - date.tm_year = (int)tp->Year - 1900; - date.tm_isdst = -1; // use auto - - ot = mktime(&date); - if (ot == (time_t) -1) - return INVALID_DATETIME_T; - - if (!Local) - ot += DateTimeTZOffset(ot); - - return LinuxToDateTime(ot); -} - bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local) { time_t ot; diff --git a/corec/corec/helpers/date/date_win32.c b/corec/corec/helpers/date/date_win32.c index ef2f8466..6e8ea5d4 100644 --- a/corec/corec/helpers/date/date_win32.c +++ b/corec/corec/helpers/date/date_win32.c @@ -135,58 +135,6 @@ datetime_t GetTimeDate() return INVALID_DATETIME_T; } -datetime_t TimePackToRel(const datepack_t *tp, bool_t Local) -{ - SYSTEMTIME TimeStruct = {0}; - FILETIME fTime; - datetime_t t; - - if (!tp) - return INVALID_DATETIME_T; - - TimeStruct.wMilliseconds = (WORD)0; - TimeStruct.wSecond = (WORD)tp->Second; - TimeStruct.wMinute = (WORD)tp->Minute; - TimeStruct.wHour = (WORD)tp->Hour; - TimeStruct.wDay = (WORD)tp->Day; - TimeStruct.wMonth = (WORD)tp->Month; - TimeStruct.wYear = (WORD)tp->Year; - TimeStruct.wDayOfWeek = (WORD)(tp->WeekDay ? tp->WeekDay-1:0); - -#ifdef TARGET_WIN2K - if (Local) - { - SYSTEMTIME sysTimeStruct; - TIME_ZONE_INFORMATION timeZoneInfo; - GetTimeZoneInformation(&timeZoneInfo); - if (!TzSpecificLocalTimeToSystemTime(&timeZoneInfo, &TimeStruct, &sysTimeStruct)) - return INVALID_DATETIME_T; - if (!SystemTimeToFileTime( &sysTimeStruct, &fTime )) - return INVALID_DATETIME_T; - } - else -#endif - if (!SystemTimeToFileTime( &TimeStruct, &fTime )) - return INVALID_DATETIME_T; - - t = FileTimeToRel(&fTime); - -#ifndef TARGET_WIN2K - if (Local) { - GetFixedTZ(); - t += fix_tz.Bias * 60; - if (GetIsDst(t)) // test with UTC time without daylight (not perfect at the edges) - t += fix_tz.DaylightBias * 60; - else - t += fix_tz.StandardBias * 60; - if (t==INVALID_DATETIME_T) - ++t; - } -#endif - - return t; -} - bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local) { SYSTEMTIME TimeStruct = {0}; From bd5088f50c1fb0fc75a90e89c4a38e9f5e026c93 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Wed, 1 Jan 2025 14:28:12 +0100 Subject: [PATCH 2/4] corec: only enable win32 GetIsDst() when TARGET_WIN2K is not defined This is currently the case. --- corec/corec/helpers/date/date_win32.c | 29 ++++----------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/corec/corec/helpers/date/date_win32.c b/corec/corec/helpers/date/date_win32.c index 6e8ea5d4..f953b449 100644 --- a/corec/corec/helpers/date/date_win32.c +++ b/corec/corec/helpers/date/date_win32.c @@ -28,7 +28,9 @@ static FILETIME fTimeCache[MAX_CACHED_YEAR - MIN_CACHED_YEAR + 2][2]; #define TIME_ZONE_ID_INVALID ((DWORD)0xFFFFFFFF) #endif +#ifndef TARGET_WIN2K static bool_t GetIsDst(datetime_t t); // may not be correct on all platforms +#endif systick_t GetTimeTick(void) { @@ -181,32 +183,9 @@ bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local) return 1; } +#ifndef TARGET_WIN2K bool_t GetIsDst(datetime_t t) { -#ifdef TARGET_WIN2K - FILETIME fTime = {0}; - TIME_ZONE_INFORMATION timeZoneInfo; - SYSTEMTIME sysTimeStruct = {0}; - SYSTEMTIME TimeStruct = {0}; - int Hour; - - if (t == INVALID_DATETIME_T) - return 0; - - RelToFileTime(t, &fTime); - if (!FileTimeToSystemTime(&fTime, &sysTimeStruct)) - return 0; - GetTimeZoneInformation(&timeZoneInfo); - if (!SystemTimeToTzSpecificLocalTime(&timeZoneInfo, &sysTimeStruct, &TimeStruct)) - return 0; - Hour = TimeStruct.wHour; - timeZoneInfo.DaylightBias = 0; - timeZoneInfo.DaylightDate.wMonth = 0; - timeZoneInfo.StandardDate.wMonth = 0; - if (!SystemTimeToTzSpecificLocalTime(&timeZoneInfo, &sysTimeStruct, &TimeStruct)) - return 0; - return Hour != TimeStruct.wHour; -#else FILETIME fTime; FILETIME fTime1, fTime2; FILETIME *fTimeStart, *fTimeEnd; @@ -263,7 +242,7 @@ bool_t GetIsDst(datetime_t t) return 0; return 1; -#endif } +#endif #endif From 259ed2f5eb808adaf184522e14881f34dc944148 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Wed, 1 Jan 2025 14:35:17 +0100 Subject: [PATCH 3/4] corec: remove unused URL parsing functions --- corec/corec/helpers/file/file.h | 3 - corec/corec/helpers/file/tools.c | 121 ------------------------------- 2 files changed, 124 deletions(-) diff --git a/corec/corec/helpers/file/file.h b/corec/corec/helpers/file/file.h index 5f13b9a7..b0a7fe02 100644 --- a/corec/corec/helpers/file/file.h +++ b/corec/corec/helpers/file/file.h @@ -36,9 +36,6 @@ FILE_DLL void RemovePathDelimiter(tchar_t* Path); FILE_DLL void AddPathDelimiter(tchar_t* Path,size_t PathLen); FILE_DLL const tchar_t* GetProtocol(const tchar_t* URL, tchar_t *_Protocol, int ProtoLen, bool_t* HasHost); FILE_DLL void SplitPath(const tchar_t* Path, tchar_t* Dir, int DirLen, tchar_t* Name, int NameLen, tchar_t* Ext, int ExtLen); -FILE_DLL void SplitURL(const tchar_t* URL, tchar_t* Mime, int MimeLen, tchar_t* Host, int HostLen, int* Port, tchar_t* Path, int PathLen); -FILE_DLL bool_t SplitAddr(const tchar_t* URL, tchar_t* Peer, int PeerLen, tchar_t* Local, int LocalLen); -FILE_DLL bool_t SetFileExt(tchar_t* URL, size_t URLLen, const tchar_t* Ext); FILE_DLL int CheckExts(const tchar_t* URL, const tchar_t* Exts); FILE_DLL void AbsPath(tchar_t* Abs, int AbsLen, const tchar_t* Path, const tchar_t* Base); FILE_DLL void AbsPathNormalize(tchar_t* Abs, size_t AbsLen); diff --git a/corec/corec/helpers/file/tools.c b/corec/corec/helpers/file/tools.c index c703878c..fea0d444 100644 --- a/corec/corec/helpers/file/tools.c +++ b/corec/corec/helpers/file/tools.c @@ -8,36 +8,6 @@ #include "file.h" #include -bool_t SetFileExt(tchar_t* URL, size_t URLLen, const tchar_t* Ext) -{ - tchar_t *p,*q,*p2; - bool_t HasHost; - - p = (tchar_t*) GetProtocol(URL,NULL,0,&HasHost); - q = p; - - p = tcsrchr(q,'\\'); - p2 = tcsrchr(q,'/'); - if (!p || (p2 && p2>p)) - p=p2; - if (p) - q = p+1; - else - if (HasHost) // only hostname - return 0; - - if (!q[0]) // no filename at all? - return 0; - - p = tcsrchr(q,'.'); - if (p) - *p = 0; - - tcscat_s(URL,URLLen,T(".")); - tcscat_s(URL,URLLen,Ext); - return 1; -} - void AddPathDelimiter(tchar_t* Path,size_t PathLen) { size_t n = tcslen(Path); @@ -104,97 +74,6 @@ const tchar_t* GetProtocol(const tchar_t* URL, tchar_t* Proto, int ProtoLen, boo return s; } -bool_t SplitAddr(const tchar_t* URL, tchar_t* Peer, int PeerLen, tchar_t* Local, int LocalLen) -{ - const tchar_t* p = NULL; - const tchar_t* p2; - const tchar_t* Addr; - bool_t HasHost; - bool_t Result = 0; - - Addr = GetProtocol(URL,NULL,0,&HasHost); - - if (HasHost) - { - p = tcschr(Addr,'\\'); - p2 = tcschr(Addr,'/'); - if (!p || (p2 && p2>p)) - p=p2; - } - if (!p) - p = Addr+tcslen(Addr); - - p2 = tcschr(Addr,'@'); - if (!p2 || p2>p) - p2 = p; - else - Result = 1; - - if (Peer) - tcsncpy_s(Peer,PeerLen,URL,p2-URL); - - if (Local) - { - if (p2p)) - p=p2; - if (!p) - p = URL+tcslen(URL); - - p2 = tcschr(URL,':'); - if (p2 && p20) - *Host = 0; - } - - if (Path) - { - if (URL[0]) - { - tchar_t* p; - tcscpy_s(Path,PathLen,URL); - for (p=Path;*p;++p) - if (*p == '\\') - *p = '/'; - } - else - tcscpy_s(Path,PathLen,T("/")); - } -} - void SplitPath(const tchar_t* URL, tchar_t* Dir, int DirLen, tchar_t* Name, int NameLen, tchar_t* Ext, int ExtLen) { const tchar_t *p,*p2,*p3; From fa15b42d7e14a8db70b45721cc551abb1b2a4ace Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Wed, 1 Jan 2025 14:35:32 +0100 Subject: [PATCH 4/4] corec: make CheckExts() non-public --- corec/corec/helpers/file/file.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/corec/corec/helpers/file/file.h b/corec/corec/helpers/file/file.h index b0a7fe02..563da0ac 100644 --- a/corec/corec/helpers/file/file.h +++ b/corec/corec/helpers/file/file.h @@ -36,13 +36,14 @@ FILE_DLL void RemovePathDelimiter(tchar_t* Path); FILE_DLL void AddPathDelimiter(tchar_t* Path,size_t PathLen); FILE_DLL const tchar_t* GetProtocol(const tchar_t* URL, tchar_t *_Protocol, int ProtoLen, bool_t* HasHost); FILE_DLL void SplitPath(const tchar_t* Path, tchar_t* Dir, int DirLen, tchar_t* Name, int NameLen, tchar_t* Ext, int ExtLen); -FILE_DLL int CheckExts(const tchar_t* URL, const tchar_t* Exts); FILE_DLL void AbsPath(tchar_t* Abs, int AbsLen, const tchar_t* Path, const tchar_t* Base); FILE_DLL void AbsPathNormalize(tchar_t* Abs, size_t AbsLen); FILE_DLL void ReduceLocalPath(tchar_t* Abs, size_t AbsLen); FILE_DLL void RelPath(tchar_t* Rel, int RelLen, const tchar_t* Path, const tchar_t* Base); FILE_DLL bool_t UpperPath(tchar_t* Path, tchar_t* Last, size_t LastLen); +int CheckExts(const tchar_t* URL, const tchar_t* Exts); + #ifdef __cplusplus } #endif