Duplicate argv data before poptFreeContext().
[rsync.git] / syscall.c
index 58a8e81514a703963fed5b577d0ba334452ae425..d92074aaadc20f595c6d381a24d6eefb0f90d416 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -4,7 +4,7 @@
  *
  * Copyright (C) 1998 Andrew Tridgell
  * Copyright (C) 2002 Martin Pool
- * Copyright (C) 2003-2020 Wayne Davison
+ * Copyright (C) 2003-2022 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -233,11 +233,13 @@ int do_chmod(const char *path, mode_t mode)
 {
        static int switch_step = 0;
        int code;
+
        if (dry_run) return 0;
        RETURN_ERROR_IF_RO_OR_LO;
+
        switch (switch_step) {
 #ifdef HAVE_LCHMOD
-#include "case_N.h"
+       case 0:
                if ((code = lchmod(path, mode & CHMOD_BITS)) == 0)
                        break;
                if (errno == ENOSYS)
@@ -245,8 +247,8 @@ int do_chmod(const char *path, mode_t mode)
                else if (errno != ENOTSUP)
                        break;
 #endif
-
-#include "case_N.h"
+               /* FALLTHROUGH */
+       default:
                if (S_ISLNK(mode)) {
 # if defined HAVE_SETATTRLIST
                        struct attrlist attrList;
@@ -255,7 +257,10 @@ int do_chmod(const char *path, mode_t mode)
                        memset(&attrList, 0, sizeof attrList);
                        attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
                        attrList.commonattr = ATTR_CMN_ACCESSMASK;
-                       code = setattrlist(path, &attrList, &m, sizeof m, FSOPT_NOFOLLOW);
+                       if ((code = setattrlist(path, &attrList, &m, sizeof m, FSOPT_NOFOLLOW)) == 0)
+                               break;
+                       if (errno == ENOTSUP)
+                               code = 1;
 # else
                        code = 1;
 # endif
@@ -415,7 +420,26 @@ int do_setattrlist_times(const char *path, STRUCT_STAT *stp)
        attrList.commonattr = ATTR_CMN_MODTIME | ATTR_CMN_ACCTIME;
        return setattrlist(path, &attrList, ts, sizeof ts, FSOPT_NOFOLLOW);
 }
+
+#ifdef SUPPORT_CRTIMES
+int do_setattrlist_crtime(const char *path, time_t crtime)
+{
+       struct attrlist attrList;
+       struct timespec ts;
+
+       if (dry_run) return 0;
+       RETURN_ERROR_IF_RO_OR_LO;
+
+       ts.tv_sec = crtime;
+       ts.tv_nsec = 0;
+
+       memset(&attrList, 0, sizeof attrList);
+       attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
+       attrList.commonattr = ATTR_CMN_CRTIME;
+       return setattrlist(path, &attrList, &ts, sizeof ts, FSOPT_NOFOLLOW);
+}
 #endif
+#endif /* HAVE_SETATTRLIST */
 
 #ifdef SUPPORT_CRTIMES
 time_t get_create_time(const char *path, STRUCT_STAT *stp)
@@ -439,24 +463,12 @@ time_t get_create_time(const char *path, STRUCT_STAT *stp)
 #endif
 }
 
-int set_create_time(const char *path, time_t crtime)
+#if defined __CYGWIN__
+int do_SetFileTime(const char *path, time_t crtime)
 {
        if (dry_run) return 0;
        RETURN_ERROR_IF_RO_OR_LO;
 
-    {
-#ifdef HAVE_GETATTRLIST
-       struct attrlist attrList;
-       struct timespec ts;
-
-       ts.tv_sec = crtime;
-       ts.tv_nsec = 0;
-
-       memset(&attrList, 0, sizeof attrList);
-       attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
-       attrList.commonattr = ATTR_CMN_CRTIME;
-       return setattrlist(path, &attrList, &ts, sizeof ts, FSOPT_NOFOLLOW);
-#elif defined __CYGWIN__
        int cnt = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
        if (cnt == 0)
            return -1;
@@ -476,9 +488,8 @@ int set_create_time(const char *path, time_t crtime)
        int ok = SetFileTime(handle, &birth_time, NULL, NULL);
        CloseHandle(handle);
        return ok ? 0 : -1;
-#endif
-    }
 }
+#endif
 #endif /* SUPPORT_CRTIMES */
 
 #ifdef HAVE_UTIMENSAT