Fix for dlfcn.rtld_next_from_library.

Using fclose to get the same address for the test assertion because
Samsung already uses LD_PRELOAD to intercept `close`.

Bug: http://b/67978141
Bug: http://b/68855476
Test: ran tests
Change-Id: I2da463e8b27e0db5cb1ba370d30f0402d7531396
Signed-off-by: Raj Mamadgi <r.mamadgi@samsung.com>
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 697b84a..794c0f2 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -1102,17 +1102,17 @@
 
 // Check that RTLD_NEXT of a libc symbol works in dlopened library
 TEST(dlfcn, rtld_next_from_library) {
-  void* library_with_close = dlopen("libtest_check_rtld_next_from_library.so", RTLD_NOW);
-  ASSERT_TRUE(library_with_close != nullptr) << dlerror();
-  void* expected_addr = dlsym(RTLD_DEFAULT, "close");
+  void* library_with_fclose = dlopen("libtest_check_rtld_next_from_library.so", RTLD_NOW);
+  ASSERT_TRUE(library_with_fclose != nullptr) << dlerror();
+  void* expected_addr = dlsym(RTLD_DEFAULT, "fclose");
   ASSERT_TRUE(expected_addr != nullptr) << dlerror();
-  typedef void* (*get_libc_close_ptr_fn_t)();
-  get_libc_close_ptr_fn_t get_libc_close_ptr =
-      reinterpret_cast<get_libc_close_ptr_fn_t>(dlsym(library_with_close, "get_libc_close_ptr"));
-  ASSERT_TRUE(get_libc_close_ptr != nullptr) << dlerror();
-  ASSERT_EQ(expected_addr, get_libc_close_ptr());
+  typedef void* (*get_libc_fclose_ptr_fn_t)();
+  get_libc_fclose_ptr_fn_t get_libc_fclose_ptr =
+      reinterpret_cast<get_libc_fclose_ptr_fn_t>(dlsym(library_with_fclose, "get_libc_fclose_ptr"));
+  ASSERT_TRUE(get_libc_fclose_ptr != nullptr) << dlerror();
+  ASSERT_EQ(expected_addr, get_libc_fclose_ptr());
 
-  dlclose(library_with_close);
+  dlclose(library_with_fclose);
 }
 
 
diff --git a/tests/libs/check_rtld_next_from_library.cpp b/tests/libs/check_rtld_next_from_library.cpp
index 45d8eea..fb15e2a 100644
--- a/tests/libs/check_rtld_next_from_library.cpp
+++ b/tests/libs/check_rtld_next_from_library.cpp
@@ -15,22 +15,23 @@
  */
 
 #include <dlfcn.h>
+#include <stdio.h>
 #include <stdlib.h>
 
-static void* g_libc_close_ptr;
+static void* g_libc_fclose_ptr;
 
-static void __attribute__((constructor)) __libc_close_lookup() {
-  g_libc_close_ptr = dlsym(RTLD_NEXT, "close");
+static void __attribute__((constructor)) __libc_fclose_lookup() {
+  g_libc_fclose_ptr = dlsym(RTLD_NEXT, "fclose");
 }
 
-// A libc function used for RTLD_NEXT
-// This function in not supposed to be called
-extern "C" int __attribute__((weak)) close(int) {
+// A libc function used for RTLD_NEXT.
+// This function in not supposed to be called.
+extern "C" int __attribute__((weak)) fclose(FILE*) {
   abort();
 }
 
-extern "C" void* get_libc_close_ptr() {
-  return g_libc_close_ptr;
+extern "C" void* get_libc_fclose_ptr() {
+  return g_libc_fclose_ptr;
 }