Add hasmntopt(3)

bionic has the Linux-specific mntent.h but is missing hasmntopt().

Change-Id: I0ab7b83626c969704add4e64b37a6fc715d4a723
Signed-off-by: Greg Hackmann <ghackmann@google.com>
diff --git a/tests/mntent_test.cpp b/tests/mntent_test.cpp
index a102849..3fb2f86 100644
--- a/tests/mntent_test.cpp
+++ b/tests/mntent_test.cpp
@@ -38,3 +38,20 @@
 
   ASSERT_EQ(1, endmntent(fp));
 }
+
+TEST(mntent, hasmntopt) {
+  // indices                  1  1
+  // of keys:      0    5   9 1  4
+  char mnt_opts[]{"aa=b,a=b,b,bb,c=d"};
+  struct mntent ent;
+  memset(&ent, 0, sizeof(ent));
+  ent.mnt_opts = mnt_opts;
+
+  EXPECT_EQ(mnt_opts, hasmntopt(&ent, "aa"));
+  EXPECT_EQ(mnt_opts + 5, hasmntopt(&ent, "a"));
+  EXPECT_EQ(mnt_opts + 9, hasmntopt(&ent, "b"));
+  EXPECT_EQ(mnt_opts + 11, hasmntopt(&ent, "bb"));
+  EXPECT_EQ(mnt_opts + 14, hasmntopt(&ent, "c"));
+  EXPECT_EQ(nullptr, hasmntopt(&ent, "d"));
+  EXPECT_EQ(nullptr, hasmntopt(&ent, "e"));
+}