]>
git.proxmox.com Git - libgit2.git/blob - src/path.h
2 * Copyright (C) 2009-2011 the libgit2 contributors
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.
7 #ifndef INCLUDE_path_h__
8 #define INCLUDE_path_h__
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.
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 "." .
23 * The `git_path_dirname` implementation is thread safe. The returned
24 * string must be manually free'd.
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).
31 extern char *git_path_dirname(const char *path
);
32 extern int git_path_dirname_r(git_buf
*buffer
, const char *path
);
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.
40 * Trailing slashes and backslashes are significant: the basename of
41 * c:/foo/bar/ is an empty string after the rightmost slash.
43 * The `git_path_basename` implementation is thread safe. The returned
44 * string must be manually free'd.
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).
50 extern char *git_path_basename(const char *path
);
51 extern int git_path_basename_r(git_buf
*buffer
, const char *path
);
53 extern const char *git_path_topdir(const char *path
);
55 extern int git_path_root(const char *path
);
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
);
60 extern int git_path_to_dir(git_buf
*path
);
61 extern void git_path_string_to_dir(char* path
, size_t size
);
64 GIT_INLINE(void) git_path_mkposix(char *path
)
74 # define git_path_mkposix(p) /* blank */
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
);