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/filebuf.c | |
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/filebuf.c')
-rw-r--r-- | src/filebuf.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index 6600bfa4b..aa47d5eb0 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -196,18 +196,19 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags) /* If we are writing to a temp file */ if (flags & GIT_FILEBUF_TEMPORARY) { - char tmp_path[GIT_PATH_MAX]; + git_buf tmp_path = GIT_BUF_INIT; /* Open the file as temporary for locking */ - file->fd = git_futils_mktmp(tmp_path, path); + file->fd = git_futils_mktmp(&tmp_path, path); if (file->fd < 0) { + git_buf_free(&tmp_path); error = GIT_EOSERR; goto cleanup; } /* No original path */ file->path_original = NULL; - file->path_lock = git__strdup(tmp_path); + file->path_lock = git_buf_detach(&tmp_path); if (file->path_lock == NULL) { error = GIT_ENOMEM; |