]> git.proxmox.com Git - libgit2.git/blob - src/path.h
Merge pull request #405 from carlosmn/http-ls
[libgit2.git] / src / path.h
1 /*
2 * Copyright (C) 2009-2011 the libgit2 contributors
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_path_h__
8 #define INCLUDE_path_h__
9
10 #include "common.h"
11
12 /*
13 * The dirname() function shall take a pointer to a character string
14 * that contains a pathname, and return a pointer to a string that is a
15 * pathname of the parent directory of that file. Trailing '/' characters
16 * in the path are not counted as part of the path.
17 *
18 * If path does not contain a '/', then dirname() shall return a pointer to
19 * the string ".". If path is a null pointer or points to an empty string,
20 * dirname() shall return a pointer to the string "." .
21 *
22 * The `git_path_dirname` implementation is thread safe. The returned
23 * string must be manually free'd.
24 *
25 * The `git_path_dirname_r` implementation expects a string allocated
26 * by the user with big enough size.
27 */
28 extern char *git_path_dirname(const char *path);
29 extern int git_path_dirname_r(char *buffer, size_t bufflen, const char *path);
30
31 /*
32 * This function returns the basename of the file, which is the last
33 * part of its full name given by fname, with the drive letter and
34 * leading directories stripped off. For example, the basename of
35 * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
36 *
37 * Trailing slashes and backslashes are significant: the basename of
38 * c:/foo/bar/ is an empty string after the rightmost slash.
39 *
40 * The `git_path_basename` implementation is thread safe. The returned
41 * string must be manually free'd.
42 *
43 * The `git_path_basename_r` implementation expects a string allocated
44 * by the user with big enough size.
45 */
46 extern char *git_path_basename(const char *path);
47 extern int git_path_basename_r(char *buffer, size_t bufflen, const char *path);
48
49 extern const char *git_path_topdir(const char *path);
50
51 /**
52 * Join two paths together. Takes care of properly fixing the
53 * middle slashes and everything
54 *
55 * The paths are joined together into buffer_out; this is expected
56 * to be an user allocated buffer of `GIT_PATH_MAX` size
57 */
58 extern void git_path_join_n(char *buffer_out, int npath, ...);
59
60 GIT_INLINE(void) git_path_join(char *buffer_out, const char *path_a, const char *path_b)
61 {
62 git_path_join_n(buffer_out, 2, path_a, path_b);
63 }
64
65 int git_path_root(const char *path);
66
67 int git_path_prettify(char *path_out, const char *path, const char *base);
68 int git_path_prettify_dir(char *path_out, const char *path, const char *base);
69
70 #ifdef GIT_WIN32
71 GIT_INLINE(void) git_path_mkposix(char *path)
72 {
73 while (*path) {
74 if (*path == '\\')
75 *path = '/';
76
77 path++;
78 }
79 }
80 #else
81 # define git_path_mkposix(p) /* blank */
82 #endif
83
84 #endif