diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-02-05 13:12:02 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-02-05 13:12:02 +0200 |
| commit | 412b3887761be5e8910b824c81b6f3637137446c (patch) | |
| tree | 96eb9b8260632db3e4e08974870c795c096d7eed /src/util.c | |
| parent | f725931b4865317b58c1f1600724cb36e586c332 (diff) | |
| download | libgit2-412b3887761be5e8910b824c81b6f3637137446c.tar.gz | |
Add new utility method `git__joinpath`
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index d9d77eccf..e1f709962 100644 --- a/src/util.c +++ b/src/util.c @@ -202,6 +202,30 @@ const char *git__topdir(const char *path) return &path[i + 1]; } +char *git__joinpath(const char *path_a, const char *path_b) +{ + int len_a, len_b; + char *path_new; + + len_a = strlen(path_a); + len_b = strlen(path_b); + + path_new = git__malloc(len_a + len_b + 2); + if (path_new == NULL) + return NULL; + + strcpy(path_new, path_a); + + if (path_new[len_a - 1] != '/') + path_new[len_a++] = '/'; + + if (path_b[0] == '/') + path_b++; + + strcpy(path_new + len_a, path_b); + return path_new; +} + static char *strtok_raw(char *output, char *src, char *delimit, int keep) { while (*src && strchr(delimit, *src) == NULL) |
