summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2014-11-14 23:45:44 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-11-14 23:45:45 +0000
commit661423a453b2692d592df56307a876dfc35c50f2 (patch)
tree6526acffcca10d34b9e31c94771aa9515f78f1b5
parent4cf942d318f2856dff078798ce9a3eac5de593b7 (diff)
parentb5e581abfe28de8ed6c8c8af1c265bb4e36f97bb (diff)
downloadbionic-661423a453b2692d592df56307a876dfc35c50f2.zip
bionic-661423a453b2692d592df56307a876dfc35c50f2.tar.gz
bionic-661423a453b2692d592df56307a876dfc35c50f2.tar.bz2
Merge "Increase support of pathconf options."
-rw-r--r--libc/bionic/pathconf.cpp10
-rw-r--r--tests/unistd_test.cpp21
2 files changed, 28 insertions, 3 deletions
diff --git a/libc/bionic/pathconf.cpp b/libc/bionic/pathconf.cpp
index de9e022..e6f5742 100644
--- a/libc/bionic/pathconf.cpp
+++ b/libc/bionic/pathconf.cpp
@@ -100,12 +100,16 @@ static long __pathconf(const struct statfs& s, int name) {
case _PC_2_SYMLINKS:
return __2_symlinks(s);
+ case _PC_ALLOC_SIZE_MIN: /* fall through */
+ case _PC_REC_XFER_ALIGN:
+ return s.f_frsize;
+
+ case _PC_REC_MIN_XFER_SIZE:
+ return s.f_bsize;
+
#if 0
- case _PC_ALLOC_SIZE_MIN:
case _PC_REC_INCR_XFER_SIZE:
case _PC_REC_MAX_XFER_SIZE:
- case _PC_REC_MIN_XFER_SIZE:
- case _PC_REC_XFER_ALIGN:
#endif
case _PC_SYMLINK_MAX:
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index c9d9943..b5fcf26 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <limits.h>
#include <stdint.h>
+#include <sys/param.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/utsname.h>
@@ -499,3 +500,23 @@ TEST(unistd, gethostname) {
ASSERT_EQ(-1, gethostname(hostname, strlen(hostname)));
ASSERT_EQ(ENAMETOOLONG, errno);
}
+
+TEST(unistd, pathconf_fpathconf) {
+ TemporaryFile tf;
+ long rc = 0L;
+ // As a file system's block size is always power of 2, the configure values
+ // for ALLOC and XFER should be power of 2 as well.
+ rc = pathconf(tf.filename, _PC_ALLOC_SIZE_MIN);
+ ASSERT_TRUE(rc > 0 && powerof2(rc));
+ rc = pathconf(tf.filename, _PC_REC_MIN_XFER_SIZE);
+ ASSERT_TRUE(rc > 0 && powerof2(rc));
+ rc = pathconf(tf.filename, _PC_REC_XFER_ALIGN);
+ ASSERT_TRUE(rc > 0 && powerof2(rc));
+
+ rc = fpathconf(tf.fd, _PC_ALLOC_SIZE_MIN);
+ ASSERT_TRUE(rc > 0 && powerof2(rc));
+ rc = fpathconf(tf.fd, _PC_REC_MIN_XFER_SIZE);
+ ASSERT_TRUE(rc > 0 && powerof2(rc));
+ rc = fpathconf(tf.fd, _PC_REC_XFER_ALIGN);
+ ASSERT_TRUE(rc > 0 && powerof2(rc));
+}