From 4fcc86b07db26da17f17af0fd777cab78fcaaf4c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 19 Feb 2009 20:10:49 +0100 Subject: Introduce the function strip_path_suffix() The function strip_path_suffix() will try to strip a given suffix from a given path. The suffix must start at a directory boundary (i.e. "core" is not a path suffix of "libexec/git-core", but "git-core" is). Arbitrary runs of directory separators ("slashes") are assumed identical. Example: strip_path_suffix("C:\\msysgit/\\libexec\\git-core", "libexec///git-core", &prefix) will set prefix to "C:\\msysgit" and return 0. Signed-off-by: Johannes Schindelin Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- test-path-utils.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test-path-utils.c') diff --git a/test-path-utils.c b/test-path-utils.c index 5168a8e3df..d261398d6c 100644 --- a/test-path-utils.c +++ b/test-path-utils.c @@ -26,6 +26,12 @@ int main(int argc, char **argv) return 0; } + if (argc == 4 && !strcmp(argv[1], "strip_path_suffix")) { + char *prefix = strip_path_suffix(argv[2], argv[3]); + printf("%s\n", prefix ? prefix : "(null)"); + return 0; + } + fprintf(stderr, "%s: unknown function name: %s\n", argv[0], argv[1] ? argv[1] : "(there was none)"); return 1; -- cgit v1.2.1