Move the utime() wrapper from test-chmtime.c to mingw.c.

The recent commit f746bae84e uses utime() to
adjust time stamps of pack files. We better make sure that we have an
implementation of utime that sets time stamps in a fashion that works with
our stat() implementation. (The system's utime() implemenation has issues
with daylight saving time changes.)

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This commit is contained in:
Johannes Sixt
2008-03-18 09:18:53 +01:00
parent 49133c8b09
commit 04d1197343
3 changed files with 30 additions and 32 deletions

View File

@@ -175,6 +175,33 @@ int mingw_fstat(int fd, struct mingw_stat *buf)
return -1;
}
static inline void time_t_to_filetime(time_t t, FILETIME *ft)
{
long long winTime = t * 10000000LL + 116444736000000000LL;
ft->dwLowDateTime = winTime;
ft->dwHighDateTime = winTime >> 32;
}
int mingw_utime (const char *file_name, const struct utimbuf *times)
{
FILETIME mft, aft;
int fh, rc;
/* must have write permission */
if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0)
return -1;
time_t_to_filetime(times->modtime, &mft);
time_t_to_filetime(times->actime, &aft);
if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
errno = EINVAL;
rc = -1;
} else
rc = 0;
close(fh);
return rc;
}
unsigned int sleep (unsigned int seconds)
{
Sleep(seconds*1000);

View File

@@ -174,6 +174,9 @@ int mingw_fstat(int fd, struct mingw_stat *buf);
static inline int mingw_stat(const char *file_name, struct mingw_stat *buf)
{ return mingw_lstat(file_name, buf); }
int mingw_utime(const char *file_name, const struct utimbuf *times);
#define utime mingw_utime
pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env);
void mingw_execvp(const char *cmd, char *const *argv);
#define execvp mingw_execvp

View File

@@ -3,38 +3,6 @@
static const char usage_str[] = "(+|=|=+|=-|-)<seconds> <file>...";
#ifdef __MINGW32__
static inline void time_t_to_filetime(time_t t, FILETIME *ft)
{
long long winTime = t * 10000000LL + 116444736000000000LL;
ft->dwLowDateTime = winTime;
ft->dwHighDateTime = winTime >> 32;
}
int git_utime (const char *file_name, const struct utimbuf *times)
{
FILETIME mft, aft;
int fh, rc;
/* must have write permission */
if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0)
return -1;
time_t_to_filetime(times->modtime, &mft);
time_t_to_filetime(times->actime, &aft);
if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
errno = EINVAL;
rc = -1;
} else
rc = 0;
close(fh);
return rc;
}
int git_utime(const char *file_name, const struct utimbuf *times);
#define utime git_utime
#endif /* __MINGW32__ */
int main(int argc, const char *argv[])
{
int i;