]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - src/libadacl.c
libadacl: improve safe_open() error message when given bad args.
[apply-default-acl.git] / src / libadacl.c
index 28d5782157f547b4a3b2b9dffebafc6f83db1cb5..1fb54a87bc8233b8a33bb08c20be1c17ae42be21 100644 (file)
@@ -8,21 +8,20 @@
 /* Enables get_current_dir_name() in unistd.h */
 #define _GNU_SOURCE
 
-#include <errno.h>
-#include <fcntl.h>
-#include <libgen.h> /* basename(), dirname() */
-#include <limits.h> /* PATH_MAX */
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h> /* get_current_dir_name() */
+#include <errno.h>    /* ELOOP, EINVAL, etc. */
+#include <fcntl.h>    /* openat() */
+#include <libgen.h>   /* basename(), dirname() */
+#include <limits.h>   /* PATH_MAX */
+#include <stdbool.h>  /* the "bool" type */
+#include <stdio.h>    /* perror(), snprintf() */
+#include <stdlib.h>   /* free() */
+#include <string.h>   /* strdup() */
+#include <sys/stat.h> /* fstat() */
+#include <unistd.h>   /* get_current_dir_name() */
 
 /* ACLs */
 #include <acl/libacl.h> /* acl_get_perm, not portable */
-#include <sys/types.h>
-#include <sys/acl.h>
+#include <sys/acl.h>    /* all other acl_foo functions */
 
 #include "libadacl.h"
 
@@ -103,7 +102,8 @@ int safe_open_ex(int at_fd, char* pathname, int flags) {
  */
 int safe_open(const char* pathname, int flags) {
   if (pathname == NULL || strlen(pathname) == 0 || pathname[0] == '\0') {
-    /* error? */
+    errno = EINVAL;
+    perror("safe_open (args)");
     return OPEN_ERROR;
   }