]>
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__
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.
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 "." .
22 * The `git_path_dirname` implementation is thread safe. The returned
23 * string must be manually free'd.
25 * The `git_path_dirname_r` implementation expects a string allocated
26 * by the user with big enough size.
28 extern char *git_path_dirname(const char *path
);
29 extern int git_path_dirname_r(char *buffer
, size_t bufflen
, const char *path
);
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.
37 * Trailing slashes and backslashes are significant: the basename of
38 * c:/foo/bar/ is an empty string after the rightmost slash.
40 * The `git_path_basename` implementation is thread safe. The returned
41 * string must be manually free'd.
43 * The `git_path_basename_r` implementation expects a string allocated
44 * by the user with big enough size.
46 extern char *git_path_basename(const char *path
);
47 extern int git_path_basename_r(char *buffer
, size_t bufflen
, const char *path
);
49 extern const char *git_path_topdir(const char *path
);
52 * Join two paths together. Takes care of properly fixing the
53 * middle slashes and everything
55 * The paths are joined together into buffer_out; this is expected
56 * to be an user allocated buffer of `GIT_PATH_MAX` size
58 extern void git_path_join_n(char *buffer_out
, int npath
, ...);
60 GIT_INLINE(void) git_path_join(char *buffer_out
, const char *path_a
, const char *path_b
)
62 git_path_join_n(buffer_out
, 2, path_a
, path_b
);
65 int git_path_root(const char *path
);
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
);
71 GIT_INLINE(void) git_path_mkposix(char *path
)
81 # define git_path_mkposix(p) /* blank */