From efac4bfe0b2bdd21a27c94ca3464046e9c23f0e4 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 12 Feb 2019 13:56:16 -0800 Subject: Add a new function child_path. child_path returns a pointer to the first component in a child path that comes after a parent path. This does not depend on trying to stat() the paths since they may describe remote paths but instead relies on filename parsing. The function requires that the child path describe a filename that contains at least one component below the parent path and returns a pointer to the first component. gdb/ChangeLog: * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/child-path-selftests.c. * common/pathstuff.c (child_path): New function. * common/pathstuff.h (child_path): New prototype. * unittests/child-path-selftests.c: New file. --- gdb/common/pathstuff.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gdb/common/pathstuff.h') diff --git a/gdb/common/pathstuff.h b/gdb/common/pathstuff.h index c264e78..67072a4 100644 --- a/gdb/common/pathstuff.h +++ b/gdb/common/pathstuff.h @@ -48,6 +48,12 @@ extern gdb::unique_xmalloc_ptr extern gdb::unique_xmalloc_ptr gdb_abspath (const char *path); +/* If the path in CHILD is a child of the path in PARENT, return a + pointer to the first component in the CHILD's pathname below the + PARENT. Otherwise, return NULL. */ + +extern const char *child_path (const char *parent, const char *child); + /* Return whether PATH contains a directory separator character. */ extern bool contains_dir_separator (const char *path); -- cgit v1.1