summaryrefslogtreecommitdiff
path: root/src/filebuf.c
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill@shutemov.name>2011-07-18 05:11:18 +0300
committerVicent Marti <tanoku@gmail.com>2011-07-25 21:12:48 +0200
commit05a62d1a8264e724e8353684de60b46eb6853cbb (patch)
tree81a87ad8863ca6200b245cbf5fc7d3e7c274b625 /src/filebuf.c
parent76159921f45eeb1b9752e33da9a28aec9a220817 (diff)
downloadlibgit2-05a62d1a8264e724e8353684de60b46eb6853cbb.tar.gz
filebuf: update git_filebuf.write signature to take non-const buffer
z_stream.next_in is non-const. Although currently Zlib doesn't modify buffer content on deflate(), it might be change in the future. gzwrite() already modify it. To avoid this let's change signature of git_filebuf.write and rework git_filebuf_write() accordingly. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Diffstat (limited to 'src/filebuf.c')
-rw-r--r--src/filebuf.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/src/filebuf.c b/src/filebuf.c
index 1fbbaa3d4..6d398a7db 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -97,7 +97,7 @@ GIT_INLINE(int) flush_buffer(git_filebuf *file)
return result;
}
-static int write_normal(git_filebuf *file, const void *source, size_t len)
+static int write_normal(git_filebuf *file, void *source, size_t len)
{
int result = 0;
@@ -110,7 +110,7 @@ static int write_normal(git_filebuf *file, const void *source, size_t len)
return result;
}
-static int write_deflate(git_filebuf *file, const void *source, size_t len)
+static int write_deflate(git_filebuf *file, void *source, size_t len)
{
int result = Z_OK;
z_stream *zs = &file->zs;
@@ -315,24 +315,13 @@ int git_filebuf_write(git_filebuf *file, const void *buff, size_t len)
return GIT_SUCCESS;
}
- /* flush the cache if it doesn't fit */
- if (file->buf_pos > 0) {
- add_to_cache(file, buf, space_left);
+ add_to_cache(file, buf, space_left);
- if ((error = flush_buffer(file)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write to buffer");
-
- len -= space_left;
- buf += space_left;
- }
+ if ((error = flush_buffer(file)) < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to write to buffer");
- /* write too-large chunks immediately */
- if (len > file->buf_size) {
- error = file->write(file, buf, len);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write to buffer");
- return GIT_SUCCESS;
- }
+ len -= space_left;
+ buf += space_left;
}
}