Fix GNU/POSIX basename headers.
Including glibc's <libgen.h> will result in the user getting the POSIX version of basename always, regardless of when it is included relative to <string.h>. Prior to this patch, our implementation would result in the one that's included first winning. Bug: http://b/25459151 Change-Id: Id4aaf1670dad317d6bbc05763a84ee87596e8e59
This commit is contained in:
@@ -19,15 +19,6 @@
|
||||
#include <errno.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static void TestBasename(const char* in, const char* expected_out) {
|
||||
char* writable_in = (in != NULL) ? strdup(in) : NULL;
|
||||
errno = 0;
|
||||
const char* out = basename(&writable_in[0]);
|
||||
ASSERT_STREQ(expected_out, out) << in;
|
||||
ASSERT_EQ(0, errno) << in;
|
||||
free(writable_in);
|
||||
}
|
||||
|
||||
static void TestDirname(const char* in, const char* expected_out) {
|
||||
char* writable_in = (in != NULL) ? strdup(in) : NULL;
|
||||
errno = 0;
|
||||
@@ -37,21 +28,6 @@ static void TestDirname(const char* in, const char* expected_out) {
|
||||
free(writable_in);
|
||||
}
|
||||
|
||||
// Do not use basename as the test name, it's defined to another value in glibc
|
||||
// so leads to a differently named test on host versus target architectures.
|
||||
TEST(libgen, posix_basename) {
|
||||
TestBasename(NULL, ".");
|
||||
TestBasename("", ".");
|
||||
TestBasename("/usr/lib", "lib");
|
||||
TestBasename("/usr/", "usr");
|
||||
TestBasename("usr", "usr");
|
||||
TestBasename("/", "/");
|
||||
TestBasename(".", ".");
|
||||
TestBasename("..", "..");
|
||||
TestBasename("///", "/");
|
||||
TestBasename("//usr//lib//", "lib");
|
||||
}
|
||||
|
||||
TEST(libgen, dirname) {
|
||||
TestDirname(NULL, ".");
|
||||
TestDirname("", ".");
|
||||
|
||||
Reference in New Issue
Block a user