]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - src/apply-default-acl.c
Improve the error message when assign_default_acl() is fed a NULL path.
[apply-default-acl.git] / src / apply-default-acl.c
index 29ca5faa9ddde14aa8e0344b1870c2d713705770..1d590303462fc601685cfdb2aeb22f6135c6947a 100644 (file)
@@ -92,29 +92,6 @@ bool is_path_directory(const char* path) {
 }
 
 
-/**
- * @brief Determine whether or not the given file descriptor is for
- *   a directory.
- *
- * @param fd
- *   The file descriptor whose directoryness is in question.
- *
- * @return true if @c fd describes a directory, and false otherwise.
- */
-bool is_directory(int fd) {
-  if (fd <= 0) {
-    return false;
-  }
-
-  struct stat s;
-  if (fstat(fd, &s) == 0) {
-    return S_ISDIR(s.st_mode);
-  }
-  else {
-    return false;
-  }
-}
-
 
 
 /**
@@ -487,7 +464,8 @@ int any_can_execute(int fd) {
 int assign_default_acl(const char* path, acl_t acl) {
 
   if (path == NULL) {
-    errno = ENOENT;
+    errno = EINVAL;
+    perror("assign_default_acl (args)");
     return ACL_ERROR;
   }
 
@@ -641,7 +619,7 @@ int apply_default_acl(const char* path, bool no_exec_mask) {
 
   if (!no_exec_mask) {
     /* Never mask the execute bit on directories. */
-    int ace_result = any_can_execute(fd) || is_directory(fd);
+    int ace_result = any_can_execute(fd) || S_ISDIR(s.st_mode);
 
     if (ace_result == ACL_ERROR) {
       perror("apply_default_acl (any_can_execute)");