Re: [PATCH] Add a new lstat and fstat implementation based on Win32 API
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Sep 4, 2007, 12:46 UTC
- Message-ID
- <Pine.LNX.4.64.0709041324420.28586@racer.site>
- In-Reply-To
- <46DD433A.5040604@eudaptics.com>
Hi,
On Tue, 4 Sep 2007, Johannes Sixt wrote:
Show 12 quoted lines
> Johannes Schindelin schrieb: > > On Tue, 4 Sep 2007, Johannes Sixt wrote: > > > Therefore, I've pushed out a fixup patch at the top of mingw.git's devel > > > branch that converts mtime to local time > > > > On Linux, we compare to UTC to begin with, right? We should do that here, > > too... So if time(NULL) does not return UTC on MinGW, we have to wrap that > > function, too. > > According to MSDN, time(NULL) returns "the number of seconds elapsed since > [epoch] according to the system clock". Please don't ask me what "the system > clock" is.
I think I know. From my QEmu adventures I know that DOS/Windows expects the system clock to be set to local time, in contrast to _all_ other operating systems.
Show 6 quoted lines
> Reading the implementation of time(), it starts with GetLocalTime(), > determines whether daylight saving is in effect, and continues with > another round of timezone adjustment - mind you: _not_ a timezone > reversal (!!). Doesn't this look extremely bogus? > > It seems we really need a wrapper for time().
I absolutely concur. Something like this (most of it is blatantly copied from Marius' patch)?
-- snip --
diff --git a/git-compat-util.h b/git-compat-util.h index 172e828..2984319 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -470,6 +470,17 @@ static inline int git_unlink(const char *pathname) { #include <time.h> struct tm *gmtime_r(const time_t *timep, struct tm *result); struct tm *localtime_r(const time_t *timep, struct tm *result); +static inline time_t mingw_time(void *dummy) +{ + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + long long winTime = ((long long)ft.dwHighDateTime << 32) + ft.dwLowDateTime; + winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */ + winTime /= 10000000; /* Nano to seconds resolution */ + return (time_t)winTime; + +} +#define time mingw_time #define hstrerror strerror char *mingw_getcwd(char *pointer, int len); -- snap -- Ciao, Dscho