2 * Copyright (C) 2011 Joseph Adams <joeyadams3.14159@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 BDELTA_OK = 0, /* Operation succeeded. */
31 BDELTA_MEMORY = 1, /* Memory allocation failed. */
32 BDELTA_PATCH_INVALID = 2, /* Patch is malformed. */
33 BDELTA_PATCH_MISMATCH = 3, /* Patch applied to wrong original string. */
35 /* Internal error codes. These will never be returned by API functions. */
36 BDELTA_INTERNAL_DMAX_EXCEEDED = -10,
37 BDELTA_INTERNAL_INPUTS_TOO_LARGE = -11,
41 * bdelta_diff - Given two byte strings, generate a "patch" (also a byte string)
42 * that describes how to transform the old string into the new string.
44 * On success, returns BDELTA_OK, and passes a malloc'd block
45 * and its size through *patch_out and *patch_size_out.
47 * On failure, returns an error code, and clears *patch_out and *patch_size_out.
50 * const char *old = "abcabba";
51 * const char *new_ = "cbabac";
56 * rc = bdelta_diff(old, strlen(old), new_, strlen(new_), &patch, &patch_size);
57 * if (rc != BDELTA_OK) {
58 * bdelta_perror("bdelta_diff", rc);
64 BDELTAcode bdelta_diff(
65 const void *old, size_t old_size,
66 const void *new_, size_t new_size,
67 void **patch_out, size_t *patch_size_out
71 * bdelta_patch - Apply a patch produced by bdelta_diff to the
72 * old string to recover the new string.
74 * On success, returns BDELTA_OK, and passes a malloc'd block
75 * and its size through *new_out and *new_size_out.
77 * On failure, returns an error code, and clears *new_out and *new_size_out.
80 * const char *old = "abcabba";
85 * rc = bdelta_patch(old, strlen(old), patch, patch_size, &new_, &new_size);
86 * if (rc != BDELTA_OK) {
87 * bdelta_perror("bdelta_patch", rc);
90 * fwrite(new_, 1, new_size, stdout);
94 BDELTAcode bdelta_patch(
95 const void *old, size_t old_size,
96 const void *patch, size_t patch_size,
97 void **new_out, size_t *new_size_out
101 * bdelta_strerror - Return a string describing a bdelta error code.
103 const char *bdelta_strerror(BDELTAcode code);
106 * bdelta_perror - Print a bdelta error message to stderr.
108 * This function handles @s the same way perror does.
110 void bdelta_perror(const char *s, BDELTAcode code);