diff options
| author | Russell Belfer <arrbee@arrbee.com> | 2011-11-30 11:27:15 -0800 |
|---|---|---|
| committer | Russell Belfer <arrbee@arrbee.com> | 2011-12-07 23:08:15 -0800 |
| commit | 97769280ba9938ae27f6e06cbd0d5e8a768a86b9 (patch) | |
| tree | 4fe43e99acb55f904f6b586bd7c5158610f9512f /src/path.h | |
| parent | a22b14d32dd8d5f06f121aa154d45bac3b10a305 (diff) | |
| download | libgit2-97769280ba9938ae27f6e06cbd0d5e8a768a86b9.tar.gz | |
Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX
buffers on the stack for manipulating paths to use git_buf objects
instead. The patch is pretty careful not to touch the public API
for libgit2, so there are a few places that still use GIT_PATH_MAX.
This extends and changes some details of the git_buf implementation
to add a couple of extra functions and to make error handling easier.
This includes serious alterations to all the path.c functions, and
several of the fileops.c ones, too. Also, there are a number of new
functions that parallel existing ones except that use a git_buf
instead of a stack-based buffer (such as git_config_find_global_r
that exists alongsize git_config_find_global).
This also modifies the win32 version of p_realpath to allocate whatever
buffer size is needed to accommodate the realpath instead of hardcoding
a GIT_PATH_MAX limit, but that change needs to be tested still.
Diffstat (limited to 'src/path.h')
| -rw-r--r-- | src/path.h | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/src/path.h b/src/path.h index 51bedeed7..0c8cc349c 100644 --- a/src/path.h +++ b/src/path.h @@ -8,6 +8,7 @@ #define INCLUDE_path_h__ #include "common.h" +#include "buffer.h" /* * The dirname() function shall take a pointer to a character string @@ -22,11 +23,13 @@ * The `git_path_dirname` implementation is thread safe. The returned * string must be manually free'd. * - * The `git_path_dirname_r` implementation expects a string allocated - * by the user with big enough size. + * The `git_path_dirname_r` implementation writes the dirname to a `git_buf` + * if the buffer pointer is not NULL. + * It returns an error code < 0 if there is an allocation error, otherwise + * the length of the dirname (which will be > 0). */ extern char *git_path_dirname(const char *path); -extern int git_path_dirname_r(char *buffer, size_t bufflen, const char *path); +extern int git_path_dirname_r(git_buf *buffer, const char *path); /* * This function returns the basename of the file, which is the last @@ -40,32 +43,22 @@ extern int git_path_dirname_r(char *buffer, size_t bufflen, const char *path); * The `git_path_basename` implementation is thread safe. The returned * string must be manually free'd. * - * The `git_path_basename_r` implementation expects a string allocated - * by the user with big enough size. + * The `git_path_basename_r` implementation writes the basename to a `git_buf`. + * It returns an error code < 0 if there is an allocation error, otherwise + * the length of the basename (which will be >= 0). */ extern char *git_path_basename(const char *path); -extern int git_path_basename_r(char *buffer, size_t bufflen, const char *path); +extern int git_path_basename_r(git_buf *buffer, const char *path); extern const char *git_path_topdir(const char *path); -/** - * Join two paths together. Takes care of properly fixing the - * middle slashes and everything - * - * The paths are joined together into buffer_out; this is expected - * to be an user allocated buffer of `GIT_PATH_MAX` size - */ -extern void git_path_join_n(char *buffer_out, int npath, ...); - -GIT_INLINE(void) git_path_join(char *buffer_out, const char *path_a, const char *path_b) -{ - git_path_join_n(buffer_out, 2, path_a, path_b); -} +extern int git_path_root(const char *path); -int git_path_root(const char *path); +extern int git_path_prettify(git_buf *path_out, const char *path, const char *base); +extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base); -int git_path_prettify(char *path_out, const char *path, const char *base); -int git_path_prettify_dir(char *path_out, const char *path, const char *base); +extern int git_path_to_dir(git_buf *path); +extern void git_path_string_to_dir(char* path, size_t size); #ifdef GIT_WIN32 GIT_INLINE(void) git_path_mkposix(char *path) |
