bsdiff-portable

A more portable version of Colin Percival's bsdiff
git clone git://git.sgregoratto.me/bsdiff-portable
Log | Files | Refs | LICENSE

commit 6c5f6ed618179f9447f43293c7963e63a6392d88
parent edd3c4a0339a9ac5b2251e83dbe4a85f9f4863f6
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Wed, 23 Sep 2020 16:57:04 +1000

Add header file (no static), u_char -> uint8_t

Diffstat:
Mbsdiff.c | 38+++++++++++++++++++-------------------
Absdiff.h | 40++++++++++++++++++++++++++++++++++++++++
Mbspatch.c | 4+++-
3 files changed, 62 insertions(+), 20 deletions(-)

diff --git a/bsdiff.c b/bsdiff.c @@ -41,9 +41,9 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c,v 1.1 2005/08/06 01:59:05 #include <string.h> #include <unistd.h> -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#include "bsdiff.h" -static void +void split(off_t *I, off_t *V, off_t start, off_t len, off_t h) { off_t i, j, k, x, tmp, jj, kk; @@ -126,8 +126,8 @@ split(off_t *I, off_t *V, off_t start, off_t len, off_t h) split(I, V, kk, start + len - kk, h); } -static void -qsufsort(off_t *I, off_t *V, u_char *old, off_t oldsize) +void +qsufsort(off_t *I, off_t *V, uint8_t *old, off_t oldsize) { off_t buckets[256]; off_t i, h, len; @@ -166,18 +166,18 @@ qsufsort(off_t *I, off_t *V, u_char *old, off_t oldsize) split(I, V, i, len, h); i += len; len = 0; - }; - }; + } + } if (len) I[i - len] = -len; - }; + } for (i = 0; i < oldsize + 1; i++) I[V[i]] = i; } -static off_t -matchlen(u_char *old, off_t oldsize, u_char *new, off_t newsize) +off_t +matchlen(uint8_t *old, off_t oldsize, uint8_t *new, off_t newsize) { off_t i; @@ -188,8 +188,8 @@ matchlen(u_char *old, off_t oldsize, u_char *new, off_t newsize) return i; } -static off_t -search(off_t *I, u_char *old, off_t oldsize, u_char *new, off_t newsize, +off_t +search(off_t *I, uint8_t *old, off_t oldsize, uint8_t *new, off_t newsize, off_t st, off_t en, off_t *pos) { off_t x, y; @@ -205,18 +205,18 @@ search(off_t *I, u_char *old, off_t oldsize, u_char *new, off_t newsize, *pos = I[en]; return y; } - }; + } x = st + (en - st) / 2; if (memcmp(old + I[x], new, MIN(oldsize - I[x], newsize)) < 0) { return search(I, old, oldsize, new, newsize, x, en, pos); } else { return search(I, old, oldsize, new, newsize, st, x, pos); - }; + } } -static void -offtout(off_t x, u_char *buf) +void +offtout(off_t x, uint8_t *buf) { off_t y; @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) { int fd; - u_char *old, *new; + uint8_t *old, *new; off_t oldsize, newsize; off_t *I, *V; off_t scan, pos, len; @@ -266,9 +266,9 @@ main(int argc, char *argv[]) off_t overlap, Ss, lens; off_t i; off_t dblen, eblen; - u_char *db, *eb; - u_char buf[8]; - u_char header[32]; + uint8_t *db, *eb; + uint8_t buf[8]; + uint8_t header[32]; FILE *pf; BZFILE *pfbz2; int bz2err; diff --git a/bsdiff.h b/bsdiff.h @@ -0,0 +1,40 @@ +#ifndef BSDIFF_H +#define BSDIFF_H +/*- + * Copyright 2003-2005 Colin Percival + * Copyright 2020 Stephen Gregoratto + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted providing that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) + +void split(off_t *, off_t *, off_t, off_t, off_t); +void qsufsort(off_t *, off_t *, uint8_t *, off_t); +off_t matchlen(uint8_t *, off_t, uint8_t *, off_t); +off_t search(off_t *, uint8_t *, off_t, uint8_t *, off_t, off_t, + off_t, off_t *); +void offtout(off_t, uint8_t *); +off_t offtin(uint8_t *buf); +uint8_t * readfile(char *, off_t *); +#endif /* BSDIFF_H */ diff --git a/bspatch.c b/bspatch.c @@ -39,7 +39,9 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59: #include <string.h> #include <unistd.h> -static off_t +#include "bsdiff.h" + +off_t offtin(u_char *buf) { off_t y;