]> git.proxmox.com Git - libgit2.git/blob - src/path.h
Merge remote-tracking branch 'nulltoken/topix/path_fromurl' into development
[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 #include "buffer.h"
12
13 /*
14 * The dirname() function shall take a pointer to a character string
15 * that contains a pathname, and return a pointer to a string that is a
16 * pathname of the parent directory of that file. Trailing '/' characters
17 * in the path are not counted as part of the path.
18 *
19 * If path does not contain a '/', then dirname() shall return a pointer to
20 * the string ".". If path is a null pointer or points to an empty string,
21 * dirname() shall return a pointer to the string "." .
22 *
23 * The `git_path_dirname` implementation is thread safe. The returned
24 * string must be manually free'd.
25 *
26 * The `git_path_dirname_r` implementation writes the dirname to a `git_buf`
27 * if the buffer pointer is not NULL.
28 * It returns an error code < 0 if there is an allocation error, otherwise
29 * the length of the dirname (which will be > 0).
30 */
31 extern char *git_path_dirname(const char *path);
32 extern int git_path_dirname_r(git_buf *buffer, const char *path);
33
34 /*
35 * This function returns the basename of the file, which is the last
36 * part of its full name given by fname, with the drive letter and
37 * leading directories stripped off. For example, the basename of
38 * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
39 *
40 * Trailing slashes and backslashes are significant: the basename of
41 * c:/foo/bar/ is an empty string after the rightmost slash.
42 *
43 * The `git_path_basename` implementation is thread safe. The returned
44 * string must be manually free'd.
45 *
46 * The `git_path_basename_r` implementation writes the basename to a `git_buf`.
47 * It returns an error code < 0 if there is an allocation error, otherwise
48 * the length of the basename (which will be >= 0).
49 */
50 extern char *git_path_basename(const char *path);
51 extern int git_path_basename_r(git_buf *buffer, const char *path);
52
53 extern const char *git_path_topdir(const char *path);
54
55 extern int git_path_root(const char *path);
56
57 extern int git_path_prettify(git_buf *path_out, const char *path, const char *base);
58 extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base);
59
60 extern int git_path_to_dir(git_buf *path);
61 extern void git_path_string_to_dir(char* path, size_t size);
62
63 #ifdef GIT_WIN32
64 GIT_INLINE(void) git_path_mkposix(char *path)
65 {
66 while (*path) {
67 if (*path == '\\')
68 *path = '/';
69
70 path++;
71 }
72 }
73 #else
74 # define git_path_mkposix(p) /* blank */
75 #endif
76
77 extern int git__percent_decode(git_buf *decoded_out, const char *input);
78 extern int git_path_fromurl(git_buf *local_path_out, const char *file_url);
79
80 #endif