send-email: recognize absolute path on Windows
[gitweb.git] / test-chmtime.c
index d5358cbaac2022483b74366555fc9707a7d8ad97..dfe8a83261b3623e64f99ddf8dc775616771ec4d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This program can either change modification time of the given
- * file(s) or just print it. The program does not change atime nor
- * ctime (their values are explicitely preserved).
+ * file(s) or just print it. The program does not change atime or
+ * ctime (their values are explicitly preserved).
  *
  * The mtime can be changed to an absolute value:
  *
@@ -56,7 +56,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
        return 1;
 }
 
-int main(int argc, const char *argv[])
+int main(int argc, char *argv[])
 {
        static int verbose;
 
@@ -84,9 +84,18 @@ int main(int argc, const char *argv[])
                if (stat(argv[i], &sb) < 0) {
                        fprintf(stderr, "Failed to stat %s: %s\n",
                                argv[i], strerror(errno));
-                       return -1;
+                       return 1;
                }
 
+#ifdef GIT_WINDOWS_NATIVE
+               if (!(sb.st_mode & S_IWUSR) &&
+                               chmod(argv[i], sb.st_mode | S_IWUSR)) {
+                       fprintf(stderr, "Could not make user-writable %s: %s",
+                               argv[i], strerror(errno));
+                       return 1;
+               }
+#endif
+
                utb.actime = sb.st_atime;
                utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
 
@@ -98,13 +107,13 @@ int main(int argc, const char *argv[])
                if (utb.modtime != sb.st_mtime && utime(argv[i], &utb) < 0) {
                        fprintf(stderr, "Failed to modify time on %s: %s\n",
                                argv[i], strerror(errno));
-                       return -1;
+                       return 1;
                }
        }
 
        return 0;
 
 usage:
-       fprintf(stderr, "Usage: %s %s\n", argv[0], usage_str);
-       return -1;
+       fprintf(stderr, "usage: %s %s\n", argv[0], usage_str);
+       return 1;
 }