changeset 10155:3df501903792

Simplify #ifs. Put Solaris code after POSIX-like code.
author Bruno Haible <bruno@clisp.org>
date Wed, 04 Jun 2008 00:00:28 +0200
parents 148190ed341d
children 0680a35c1af0
files ChangeLog lib/copy-acl.c lib/file-has-acl.c lib/set-mode-acl.c
diffstat 4 files changed, 80 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-06-03  Bruno Haible  <bruno@clisp.org>
+
+	* lib/file-has-acl.c (file_has_acl): Put Solaris 10 code after POSIX-
+	draft code. Simplify #ifs.
+	* lib/set-mode-acl.c (qset_acl): Don't test for symlink if !USE_ACL.
+	Put Solaris code after POSIX-draft code. Fix comments regarding
+	Solaris 10, HP-UX. Mention Cygwin.
+	* lib/copy-acl.c (qcopy_acl): Simplify #ifs.
+
 2008-06-03  Eric Blake  <ebb9@byu.net>
 
 	Provide fallback for older kernels.
--- a/lib/copy-acl.c
+++ b/lib/copy-acl.c
@@ -41,7 +41,7 @@
 {
   int ret;
 
-#if USE_ACL && HAVE_ACL_GET_FILE && HAVE_ACL_SET_FILE && HAVE_ACL_FREE
+#if USE_ACL && HAVE_ACL_GET_FILE
   /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
   /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */
 
@@ -125,23 +125,20 @@
     }
   return 0;
 
-#else
+#elif USE_ACL && defined ACL_NO_TRIVIAL
+  /* Solaris 10 NFSv4 ACLs.  */
 
-# if USE_ACL && defined ACL_NO_TRIVIAL
-  /* Solaris 10 NFSv4 ACLs.  */
   acl_t *aclp = NULL;
   ret = (source_desc < 0
 	 ? acl_get (src_name, ACL_NO_TRIVIAL, &aclp)
 	 : facl_get (source_desc, ACL_NO_TRIVIAL, &aclp));
   if (ret != 0 && errno != ENOSYS)
     return -2;
-# endif
 
   ret = qset_acl (dst_name, dest_desc, mode);
   if (ret != 0)
     return -1;
 
-# if USE_ACL && defined ACL_NO_TRIVIAL
   if (aclp)
     {
       ret = (dest_desc < 0
@@ -157,9 +154,13 @@
 	}
       acl_free (aclp);
     }
-# endif
 
   return 0;
+
+#else
+
+  return qset_acl (dst_name, dest_desc, mode);
+
 #endif
 }
 
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -30,21 +30,10 @@
 int
 file_has_acl (char const *name, struct stat const *sb)
 {
+#if USE_ACL
   if (! S_ISLNK (sb->st_mode))
     {
-#if USE_ACL && HAVE_ACL_TRIVIAL
-
-      /* Solaris 10, which also has NFSv4 and ZFS style ACLs.  */
-      return acl_trivial (name);
-
-#elif USE_ACL && HAVE_ACL && defined GETACLCNT
-
-      /* Solaris 2.5 through Solaris 9, and contemporaneous versions of
-	 HP-UX and Unixware.  */
-      int n = acl (name, GETACLCNT, 0, NULL);
-      return n < 0 ? (errno == ENOSYS ? 0 : -1) : (MIN_ACL_ENTRIES < n);
-
-#elif USE_ACL && HAVE_ACL_GET_FILE && HAVE_ACL_FREE
+# if HAVE_ACL_GET_FILE
 
       /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
       /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */
@@ -77,8 +66,27 @@
       if (ret < 0)
 	return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1;
       return ret;
+
+# elif HAVE_ACL && defined GETACLCNT /* Solaris, Cygwin, not HP-UX */
+
+#  if HAVE_ACL_TRIVIAL
+
+      /* Solaris 10, which also has NFSv4 and ZFS style ACLs.  */
+      return acl_trivial (name);
+
+#  else /* Solaris, Cygwin, general case */
+
+      /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions
+	 of Unixware.  The acl() call returns the access and default ACL both
+	 at once.  */
+      int n = acl (name, GETACLCNT, 0, NULL);
+      return n < 0 ? (errno == ENOSYS ? 0 : -1) : (MIN_ACL_ENTRIES < n);
+
+#  endif
+
+# endif
+    }
 #endif
-    }
 
   /* FIXME: Add support for AIX, Irix, and Tru64.  Please see Samba's
      source/lib/sysacls.c file for fix-related ideas.  */
--- a/lib/set-mode-acl.c
+++ b/lib/set-mode-acl.c
@@ -49,9 +49,10 @@
 qset_acl (char const *name, int desc, mode_t mode)
 {
 #if USE_ACL
-# if MODE_INSIDE_ACL
-#  if HAVE_ACL_SET_FILE && HAVE_ACL_FREE
+# if HAVE_ACL_GET_FILE
   /* POSIX 1003.1e draft 17 (abandoned) specific version.  */
+  /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */
+#  if MODE_INSIDE_ACL
   /* Linux, FreeBSD, IRIX, Tru64 */
 
   /* We must also have acl_from_text and acl_delete_def_file.
@@ -138,46 +139,7 @@
     }
   return 0;
 
-#  elif defined ACL_NO_TRIVIAL
-  /* Solaris 10, with NFSv4 ACLs.  */
-  acl_t *aclp;
-  char acl_text[] = "user::---,group::---,mask:---,other:---";
-
-  if (mode & S_IRUSR) acl_text[ 6] = 'r';
-  if (mode & S_IWUSR) acl_text[ 7] = 'w';
-  if (mode & S_IXUSR) acl_text[ 8] = 'x';
-  if (mode & S_IRGRP) acl_text[17] = acl_text[26] = 'r';
-  if (mode & S_IWGRP) acl_text[18] = acl_text[27] = 'w';
-  if (mode & S_IXGRP) acl_text[19] = acl_text[28] = 'x';
-  if (mode & S_IROTH) acl_text[36] = 'r';
-  if (mode & S_IWOTH) acl_text[37] = 'w';
-  if (mode & S_IXOTH) acl_text[38] = 'x';
-
-  if (acl_fromtext (acl_text, &aclp) != 0)
-    {
-      errno = ENOMEM;
-      return -1;
-    }
-  else
-    {
-      int acl_result = (desc < 0 ? acl_set (name, aclp) : facl_set (desc, aclp));
-      int acl_errno = errno;
-      acl_free (aclp);
-      if (acl_result == 0 || acl_errno != ENOSYS)
-	{
-	  errno = acl_errno;
-	  return acl_result;
-	}
-    }
-
-  return chmod_or_fchmod (name, desc, mode);
-
-#  else /* Unknown flavor of ACLs */
-  return chmod_or_fchmod (name, desc, mode);
-#  endif
-# else /* !MODE_INSIDE_ACL */
-#  if HAVE_ACL_SET_FILE && HAVE_ACL_FREE
-  /* POSIX 1003.1e draft 17 (abandoned) specific version.  */
+#  else /* !MODE_INSIDE_ACL */
   /* MacOS X */
 
   acl_t acl;
@@ -223,9 +185,44 @@
     }
 
   return chmod_or_fchmod (name, desc, mode);
-#  else /* Unknown flavor of ACLs */
+#  endif
+
+# elif defined ACL_NO_TRIVIAL
+  /* Solaris 10, with NFSv4 ACLs.  */
+  acl_t *aclp;
+  char acl_text[] = "user::---,group::---,mask:---,other:---";
+
+  if (mode & S_IRUSR) acl_text[ 6] = 'r';
+  if (mode & S_IWUSR) acl_text[ 7] = 'w';
+  if (mode & S_IXUSR) acl_text[ 8] = 'x';
+  if (mode & S_IRGRP) acl_text[17] = acl_text[26] = 'r';
+  if (mode & S_IWGRP) acl_text[18] = acl_text[27] = 'w';
+  if (mode & S_IXGRP) acl_text[19] = acl_text[28] = 'x';
+  if (mode & S_IROTH) acl_text[36] = 'r';
+  if (mode & S_IWOTH) acl_text[37] = 'w';
+  if (mode & S_IXOTH) acl_text[38] = 'x';
+
+  if (acl_fromtext (acl_text, &aclp) != 0)
+    {
+      errno = ENOMEM;
+      return -1;
+    }
+  else
+    {
+      int acl_result = (desc < 0 ? acl_set (name, aclp) : facl_set (desc, aclp));
+      int acl_errno = errno;
+      acl_free (aclp);
+      if (acl_result == 0 || acl_errno != ENOSYS)
+	{
+	  errno = acl_errno;
+	  return acl_result;
+	}
+    }
+
   return chmod_or_fchmod (name, desc, mode);
-#  endif
+
+# else /* Unknown flavor of ACLs */
+  return chmod_or_fchmod (name, desc, mode);
 # endif
 #else /* !USE_ACL */
   return chmod_or_fchmod (name, desc, mode);