diff options
author | Edward Thomson <ethomson@microsoft.com> | 2014-04-22 14:58:33 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2014-04-22 19:08:21 -0500 |
commit | e349ed500b75349b1a525fce60dc08c8d8927ba0 (patch) | |
tree | 94feff27cae54ceeff8a8920923f1ca573d7833f /src/buffer.c | |
parent | 28750a7d98ce5e23bac5c1d119109ded8e8aab73 (diff) | |
download | libgit2-e349ed500b75349b1a525fce60dc08c8d8927ba0.tar.gz |
patch: emit binary patches (optionally)
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c index f6e34a445..5169c3e09 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -212,6 +212,42 @@ int git_buf_put_base64(git_buf *buf, const char *data, size_t len) return 0; } +static const char b85str[] = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"; + +int git_buf_put_base85(git_buf *buf, const char *data, size_t len) +{ + ENSURE_SIZE(buf, buf->size + (5 * ((len / 4) + !!(len % 4))) + 1); + + while (len) { + uint32_t acc = 0; + char b85[5]; + int i; + + for (i = 24; i >= 0; i -= 8) { + uint8_t ch = *data++; + acc |= ch << i; + + if (--len == 0) + break; + } + + for (i = 4; i >= 0; i--) { + int val = acc % 85; + acc /= 85; + + b85[i] = b85str[val]; + } + + for (i = 0; i < 5; i++) + buf->ptr[buf->size++] = b85[i]; + } + + buf->ptr[buf->size] = '\0'; + + return 0; +} + int git_buf_vprintf(git_buf *buf, const char *format, va_list ap) { int len; |