Implement the GNU basename(3) in addition to the POSIX one.
Code like perf(1) needs this. Bug: 11860789 Change-Id: I907eb448052a7b165e4012d74303330d32328cb2
This commit is contained in:
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "buffer_tests.h"
|
||||
|
||||
@@ -1287,3 +1287,22 @@ TEST(string, strchr_align) {
|
||||
TEST(string, strchr_overread) {
|
||||
RunSingleBufferOverreadTest(DoStrchrTest);
|
||||
}
|
||||
|
||||
static void TestBasename(const char* in, const char* expected_out) {
|
||||
errno = 0;
|
||||
const char* out = basename(in);
|
||||
ASSERT_STREQ(expected_out, out) << in;
|
||||
ASSERT_EQ(0, errno) << in;
|
||||
}
|
||||
|
||||
TEST(string, __gnu_basename) {
|
||||
TestBasename("", "");
|
||||
TestBasename("/usr/lib", "lib");
|
||||
TestBasename("/usr/", "");
|
||||
TestBasename("usr", "usr");
|
||||
TestBasename("/", "");
|
||||
TestBasename(".", ".");
|
||||
TestBasename("..", "..");
|
||||
TestBasename("///", "");
|
||||
TestBasename("//usr//lib//", "");
|
||||
}
|
||||
|
Reference in New Issue
Block a user