1 #include "git-compat-util.h"
4 static const char usage_str
[] = "(+|=|=+|=-|-)<seconds> <file>...";
7 static inline void time_t_to_filetime(time_t t
, FILETIME
*ft
)
9 long long winTime
= t
* 10000000LL + 116444736000000000LL;
10 ft
->dwLowDateTime
= winTime
;
11 ft
->dwHighDateTime
= winTime
>> 32;
14 int git_utime (const char *file_name
, const struct utimbuf
*times
)
19 /* must have write permission */
20 if ((fh
= open(file_name
, O_RDWR
| O_BINARY
)) < 0)
23 time_t_to_filetime(times
->modtime
, &mft
);
24 time_t_to_filetime(times
->actime
, &aft
);
25 if (!SetFileTime((HANDLE
)_get_osfhandle(fh
), NULL
, &aft
, &mft
)) {
34 int git_utime(const char *file_name
, const struct utimbuf
*times
);
35 #define utime git_utime
36 #endif /* __MINGW32__ */
38 int main(int argc
, const char *argv
[])
50 set_eq
= (*timespec
== '=') ? 1 : 0;
53 if (*timespec
== '+') {
54 set_eq
= 2; /* relative "in the future" */
58 set_time
= strtol(timespec
, &test
, 10);
60 fprintf(stderr
, "Not a base-10 integer: %s\n", argv
[1] + 1);
63 if ((set_eq
&& set_time
< 0) || set_eq
== 2) {
64 time_t now
= time(NULL
);
68 for (i
= 2; i
< argc
; i
++) {
72 if (stat(argv
[i
], &sb
) < 0) {
73 fprintf(stderr
, "Failed to stat %s: %s\n",
74 argv
[i
], strerror(errno
));
78 utb
.actime
= sb
.st_atime
;
79 utb
.modtime
= set_eq
? set_time
: sb
.st_mtime
+ set_time
;
81 if (utime(argv
[i
], &utb
) < 0) {
82 fprintf(stderr
, "Failed to modify time on %s: %s\n",
83 argv
[i
], strerror(errno
));
91 fprintf(stderr
, "Usage: %s %s\n", argv
[0], usage_str
);