diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-11-04 09:20:14 -0800 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2016-03-22 19:34:08 +0100 |
commit | 3fa764edd2a11691876153fef6523375b6e4553d (patch) | |
tree | 3e4886dc3be5c28fca98a5547f52bce6c7668071 | |
parent | e50a49ee9b0fa536afc4dd87ee19197a53bd78cd (diff) | |
download | libgit2-3fa764edd2a11691876153fef6523375b6e4553d.tar.gz |
filebuf: allow using a custom buffer size
Allow setting the buffer size on open in order to use this data
structure more generally as a spill buffer, with larger buffer sizes for
specific use-cases.
-rw-r--r-- | src/filebuf.c | 7 | ||||
-rw-r--r-- | src/filebuf.h | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index 101d5082a..6eee530ee 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -273,6 +273,11 @@ cleanup: int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode) { + return git_filebuf_open_withsize(file, path, flags, mode, WRITE_BUFFER_SIZE); +} + +int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mode_t mode, size_t size) +{ int compression, error = -1; size_t path_len, alloc_len; @@ -286,7 +291,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode if (flags & GIT_FILEBUF_DO_NOT_BUFFER) file->do_not_buffer = true; - file->buf_size = WRITE_BUFFER_SIZE; + file->buf_size = size; file->buf_pos = 0; file->fd = -1; file->last_error = BUFERR_OK; diff --git a/src/filebuf.h b/src/filebuf.h index f4d255b0a..467708d45 100644 --- a/src/filebuf.h +++ b/src/filebuf.h @@ -79,6 +79,7 @@ int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len); int git_filebuf_printf(git_filebuf *file, const char *format, ...) GIT_FORMAT_PRINTF(2, 3); int git_filebuf_open(git_filebuf *lock, const char *path, int flags, mode_t mode); +int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mode_t mode, size_t size); int git_filebuf_commit(git_filebuf *lock); int git_filebuf_commit_at(git_filebuf *lock, const char *path); void git_filebuf_cleanup(git_filebuf *lock); |