diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | libmount/src/utils.c | 19 |
2 files changed, 14 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac index 1899ec3c0..eebe92259 100644 --- a/configure.ac +++ b/configure.ac @@ -391,6 +391,7 @@ AC_CHECK_FUNCS([ \ __fpending \ secure_getenv \ __secure_getenv \ + eaccess \ err \ errx \ explicit_bzero \ diff --git a/libmount/src/utils.c b/libmount/src/utils.c index a5617e6c0..711d1683e 100644 --- a/libmount/src/utils.c +++ b/libmount/src/utils.c @@ -647,17 +647,24 @@ done: static int try_write(const char *filename) { - int fd, rc = 0; + int rc = 0; if (!filename) return -EINVAL; - fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC, - S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH); - if (fd < 0) +#ifdef HAVE_EACCESS + if (eaccess(filename, R_OK|W_OK) != 0) rc = -errno; - else - close(fd); +#else + { + int fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC, + S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH); + if (fd < 0) + rc = -errno; + else + close(fd); + } +#endif return rc; } |