summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonovan Baarda <abo@minkirri.apana.org.au>2018-02-23 16:06:29 +1100
committerDonovan Baarda <abo@minkirri.apana.org.au>2018-02-23 16:06:29 +1100
commit0bf02090b24664835c06be954a253efd34bffc37 (patch)
tree31ec698b3ff897e4233bad5214deabd5e88e88ea
parent92207b458cad6f0b98559e2a9b7df510b431d788 (diff)
downloadlibrsync-0bf02090b24664835c06be954a253efd34bffc37.tar.gz
Run 'make tidyc' over code.
-rw-r--r--src/base64.c19
-rw-r--r--src/buf.c75
-rw-r--r--src/buf.h8
-rw-r--r--src/checksum.c24
-rw-r--r--src/command.c43
-rw-r--r--src/command.h24
-rw-r--r--src/delta.c294
-rw-r--r--src/emit.c39
-rw-r--r--src/fileutil.c65
-rw-r--r--src/fileutil.h12
-rw-r--r--src/hashtable.h191
-rw-r--r--src/hex.c22
-rw-r--r--src/isprefix.c23
-rw-r--r--src/isprefix.h9
-rw-r--r--src/job.c56
-rw-r--r--src/job.h88
-rw-r--r--src/librsync.h405
-rw-r--r--src/mdfour.c192
-rw-r--r--src/mdfour.h14
-rw-r--r--src/mksum.c75
-rw-r--r--src/msg.c7
-rw-r--r--src/netint.c85
-rw-r--r--src/netint.h8
-rw-r--r--src/patch.c97
-rw-r--r--src/rdiff.c176
-rw-r--r--src/readsums.c49
-rw-r--r--src/rollsum.h15
-rw-r--r--src/scoop.c123
-rw-r--r--src/stats.c59
-rw-r--r--src/stream.c117
-rw-r--r--src/sumset.c89
-rw-r--r--src/sumset.h17
-rw-r--r--src/trace.c94
-rw-r--r--src/trace.h60
-rw-r--r--src/tube.c102
-rw-r--r--src/util.c26
-rw-r--r--src/util.h21
-rw-r--r--src/version.c1
-rw-r--r--src/whole.c79
-rw-r--r--src/whole.h4
40 files changed, 1305 insertions, 1602 deletions
diff --git a/src/base64.c b/src/base64.c
index 087af5e..374143f 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -34,14 +34,14 @@ size_t rs_unbase64(char *s)
{
char const *b64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- int bit_offset, byte_offset, idx, i, n;
- unsigned char *d = (unsigned char *) s;
- char *p;
+ int bit_offset, byte_offset, idx, i, n;
+ unsigned char *d = (unsigned char *)s;
+ char *p;
n = i = 0;
while (*s && (p = strchr(b64, *s))) {
- idx = (int) (p - b64);
+ idx = (int)(p - b64);
byte_offset = (i * 6) / 8;
bit_offset = (i * 6) % 8;
d[byte_offset] &= ~((1 << (8 - bit_offset)) - 1);
@@ -66,14 +66,14 @@ void rs_base64(unsigned char const *buf, int n, char *out)
{
char const *b64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- int bytes, i;
+ int bytes, i;
/* work out how many bytes of output there are */
bytes = ((n * 8) + 5) / 6;
for (i = 0; i < bytes; i++) {
- int byte = (i * 6) / 8;
- int bit = (i * 6) % 8;
+ int byte = (i * 6) / 8;
+ int bit = (i * 6) % 8;
if (bit < 3) {
if (byte >= n)
@@ -83,8 +83,9 @@ void rs_base64(unsigned char const *buf, int n, char *out)
if (byte + 1 == n) {
*out = b64[(buf[byte] << (bit - 2)) & 0x3F];
} else {
- *out = b64[(buf[byte] << (bit - 2) |
- buf[byte + 1] >> (10 - bit)) & 0x3F];
+ *out =
+ b64[(buf[byte] << (bit - 2) | buf[byte + 1] >> (10 - bit)) &
+ 0x3F];
}
}
out++;
diff --git a/src/buf.c b/src/buf.c
index 54f2edf..30ef508 100644
--- a/src/buf.c
+++ b/src/buf.c
@@ -23,20 +23,18 @@
| Pick a window, Jimmy, you're leaving.
*/
-
-/** \file buf.c Buffers that map between stdio file streams and librsync streams.
+/** \file buf.c Buffers that map between stdio file streams and librsync
+ * streams.
*
- * As the stream consumes input and produces output, it is
- * refilled from appropriate input and output FILEs. A dynamically
- * allocated buffer of configurable size is used as an intermediary.
+ * As the stream consumes input and produces output, it is refilled from
+ * appropriate input and output FILEs. A dynamically allocated buffer of
+ * configurable size is used as an intermediary.
*
- * \todo Perhaps be more efficient by filling the buffer on every call
- * even if not yet completely empty. Check that it's really our
- * buffer, and shuffle remaining data down to the front.
+ * \todo Perhaps be more efficient by filling the buffer on every call even if
+ * not yet completely empty. Check that it's really our buffer, and shuffle
+ * remaining data down to the front.
*
- * \todo Perhaps expose a routine for shuffling the buffers.
- */
-
+ * \todo Perhaps expose a routine for shuffling the buffers. */
#include "config.h"
#include <sys/types.h>
@@ -54,12 +52,11 @@
#include "util.h"
struct rs_filebuf {
- FILE *f;
- char *buf;
- size_t buf_len;
+ FILE *f;
+ char *buf;
+ size_t buf_len;
};
-
rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len)
{
rs_filebuf_t *pf = rs_alloc_struct(rs_filebuf_t);
@@ -71,29 +68,24 @@ rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len)
return pf;
}
-
void rs_filebuf_free(rs_filebuf_t *fb)
{
- free(fb->buf);
- rs_bzero(fb, sizeof *fb);
- free(fb);
+ free(fb->buf);
+ rs_bzero(fb, sizeof *fb);
+ free(fb);
}
-
-/*
- * If the stream has no more data available, read some from F into
- * BUF, and let the stream use that. On return, SEEN_EOF is true if
- * the end of file has passed into the stream.
- */
-rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
- void *opaque)
+/* If the stream has no more data available, read some from F into BUF, and let
+ the stream use that. On return, SEEN_EOF is true if the end of file has
+ passed into the stream. */
+rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf, void *opaque)
{
- size_t len;
- rs_filebuf_t *fb = (rs_filebuf_t *) opaque;
- FILE *f = fb->f;
+ size_t len;
+ rs_filebuf_t *fb = (rs_filebuf_t *)opaque;
+ FILE *f = fb->f;
- /* This is only allowed if either the buf has no input buffer
- * yet, or that buffer could possibly be BUF. */
+ /* This is only allowed if either the buf has no input buffer yet, or that
+ buffer could possibly be BUF. */
if (buf->next_in != NULL) {
assert(buf->avail_in <= fb->buf_len);
assert(buf->next_in >= fb->buf);
@@ -109,8 +101,7 @@ rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
}
if (buf->avail_in)
- /* Still some data remaining. Perhaps we should read
- anyhow? */
+ /* Still some data remaining. Perhaps we should read anyhow? */
return RS_DONE;
len = fread(fb->buf, 1, fb->buf_len, f);
@@ -125,7 +116,8 @@ rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
rs_error("error filling buf from file: %s", strerror(errno));
return RS_IO_ERROR;
} else {
- rs_error("no error bit, but got "FMT_SIZE" return when trying to read", len);
+ rs_error("no error bit, but got " FMT_SIZE
+ " return when trying to read", len);
return RS_IO_ERROR;
}
}
@@ -137,20 +129,17 @@ rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
return RS_DONE;
}
-
-/*
- * The buf is already using BUF for an output buffer, and probably
- * contains some buffered output now. Write this out to F, and reset
- * the buffer cursor.
+/* The buf is already using BUF for an output buffer, and probably contains
+ some buffered output now. Write this out to F, and reset the buffer cursor.
*/
rs_result rs_outfilebuf_drain(rs_job_t *job, rs_buffers_t *buf, void *opaque)
{
int present;
- rs_filebuf_t *fb = (rs_filebuf_t *) opaque;
+ rs_filebuf_t *fb = (rs_filebuf_t *)opaque;
FILE *f = fb->f;
- /* This is only allowed if either the buf has no output buffer
- * yet, or that buffer could possibly be BUF. */
+ /* This is only allowed if either the buf has no output buffer yet, or that
+ buffer could possibly be BUF. */
if (buf->next_out == NULL) {
assert(buf->avail_out == 0);
diff --git a/src/buf.h b/src/buf.h
index 78f4d3d..331e9a9 100644
--- a/src/buf.h
+++ b/src/buf.h
@@ -1,19 +1,19 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- the library for network deltas
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/checksum.c b/src/checksum.c
index cdc68c7..0149ef4 100644
--- a/src/checksum.c
+++ b/src/checksum.c
@@ -32,7 +32,6 @@
#include "rollsum.h"
#include "blake2.h"
-
/** A simple 32bit checksum that can be incrementally updated. */
rs_weak_sum_t rs_calc_weak_sum(void const *buf, size_t len)
{
@@ -43,23 +42,20 @@ rs_weak_sum_t rs_calc_weak_sum(void const *buf, size_t len)
return RollsumDigest(&sum);
}
-
-/**
- * Calculate and store into SUM a strong MD4 checksum of the file
- * blocks seen so far.
+/** Calculate and store into SUM a strong MD4 checksum of the file blocks seen
+ * so far.
*
- * In plain rsync, the checksum is perturbed by a seed value. This is
- * used when retrying a failed transmission: we've discovered that the
- * hashes collided at some point, so we're going to try again with
- * different hashes to see if we can get it right. (Check tridge's
- * thesis for details and to see if that's correct.)
+ * In plain rsync, the checksum is perturbed by a seed value. This is used
+ * when retrying a failed transmission: we've discovered that the hashes
+ * collided at some point, so we're going to try again with different hashes to
+ * see if we can get it right. (Check tridge's thesis for details and to see
+ * if that's correct.)
*
- * Since we can't retry a web transaction I'm not sure if it's very
- * useful in rproxy.
- */
+ * Since we can't retry a web transaction I'm not sure if it's very useful in
+ * rproxy. */
void rs_calc_md4_sum(void const *buf, size_t len, rs_strong_sum_t *sum)
{
- rs_mdfour((unsigned char *) sum, buf, len);
+ rs_mdfour((unsigned char *)sum, buf, len);
}
void rs_calc_blake2_sum(void const *buf, size_t len, rs_strong_sum_t *sum)
diff --git a/src/command.c b/src/command.c
index 189ff40..7c6c81c 100644
--- a/src/command.c
+++ b/src/command.c
@@ -1,19 +1,19 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- the library for network deltas
- *
+ *
* Copyright (C) 2000 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -30,30 +30,25 @@
/* For debugging purposes, here are some human-readable forms. */
struct rs_op_kind_name const rs_op_kind_names[] = {
- {"END", RS_KIND_END },
- {"COPY", RS_KIND_COPY },
- {"LITERAL", RS_KIND_LITERAL },
- {"SIGNATURE", RS_KIND_SIGNATURE },
- {"CHECKSUM", RS_KIND_CHECKSUM },
- {"INVALID", RS_KIND_INVALID },
- {NULL, 0 }
+ {"END", RS_KIND_END},
+ {"COPY", RS_KIND_COPY},
+ {"LITERAL", RS_KIND_LITERAL},
+ {"SIGNATURE", RS_KIND_SIGNATURE},
+ {"CHECKSUM", RS_KIND_CHECKSUM},
+ {"INVALID", RS_KIND_INVALID},
+ {NULL, 0}
};
-
-/**
- * Return a human-readable name for KIND.
- */
-char const * rs_op_kind_name(enum rs_op_kind kind)
+/** Return a human-readable name for KIND. */
+char const *rs_op_kind_name(enum rs_op_kind kind)
{
- const struct rs_op_kind_name *k;
+ const struct rs_op_kind_name *k;
- for (k = rs_op_kind_names; k->kind; k++) {
- if (k->kind == kind) {
- return k->name;
- }
+ for (k = rs_op_kind_names; k->kind; k++) {
+ if (k->kind == kind) {
+ return k->name;
}
+ }
- return NULL;
+ return NULL;
}
-
-
diff --git a/src/command.h b/src/command.h
index 6da530c..03e0e1d 100644
--- a/src/command.h
+++ b/src/command.h
@@ -20,18 +20,13 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
/** \file command.h Types of commands present in the encoding stream.
*
- * The vague idea is that eventually this file will be more abstract
- * than protocol.h, but it's not clear that will ever be required.
- */
-
+ * The vague idea is that eventually this file will be more abstract than
+ * protocol.h, but it's not clear that will ever be required. */
-/**
- * Classes of operation that can be present. Each may have several different
- * possible representations.
- */
+/** Classes of operation that can be present. Each may have several different
+ * possible representations. */
enum rs_op_kind {
RS_KIND_END = 1000,
RS_KIND_LITERAL,
@@ -40,15 +35,14 @@ enum rs_op_kind {
RS_KIND_CHECKSUM,
RS_KIND_RESERVED, /* for future expansion */
- /* This one should never occur in file streams. It's an
- * internal marker for invalid commands. */
+ /* This one should never occur in file streams. It's an internal marker
+ for invalid commands. */
RS_KIND_INVALID
};
-
typedef struct rs_op_kind_name {
- char const *name;
- enum rs_op_kind const kind;
+ char const *name;
+ enum rs_op_kind const kind;
} rs_op_kind_name_t;
-char const * rs_op_kind_name(enum rs_op_kind);
+char const *rs_op_kind_name(enum rs_op_kind);
diff --git a/src/delta.c b/src/delta.c
index de20896..417c77d 100644
--- a/src/delta.c
+++ b/src/delta.c
@@ -26,34 +26,31 @@
| MINING!!
*/
-
/** \file delta.c -- Generate in streaming mode an rsync delta given a set of
* signatures, and a new file.
*
- * The size of blocks for signature generation is determined by the
- * block size in the incoming signature.
+ * The size of blocks for signature generation is determined by the block size
+ * in the incoming signature.
*
- * To calculate a signature, we need to be able to see at least one
- * block of the new file at a time. Once we have that, we calculate
- * its weak signature, and see if there is any block in the signature
- * hash table that has the same weak sum. If there is one, then we
- * also compute the strong sum of the new block, and cross check that.
- * If they're the same, then we can assume we have a match.
+ * To calculate a signature, we need to be able to see at least one block of
+ * the new file at a time. Once we have that, we calculate its weak signature,
+ * and see if there is any block in the signature hash table that has the same
+ * weak sum. If there is one, then we also compute the strong sum of the new
+ * block, and cross check that. If they're the same, then we can assume we have
+ * a match.
*
- * The final block of the file has to be handled a little differently,
- * because it may be a short match. Short blocks in the signature
- * don't include their length -- we just allow for the final short
- * block of the file to match any block in the signature, and if they
- * have the same checksum we assume they must have the same length.
- * Therefore, when we emit a COPY command, we have to send it with a
- * length that is the same as the block matched, and not the block
- * length from the signature.
+ * The final block of the file has to be handled a little differently, because
+ * it may be a short match. Short blocks in the signature don't include their
+ * length -- we just allow for the final short block of the file to match any
+ * block in the signature, and if they have the same checksum we assume they
+ * must have the same length. Therefore, when we emit a COPY command, we have
+ * to send it with a length that is the same as the block matched, and not the
+ * block length from the signature.
*
* Profiling results as of v1.26, 2001-03-18:
*
- * If everything matches, then we spend almost all our time in
- * rs_mdfour64 and rs_weak_sum, which is unavoidable and therefore a
- * good profile.
+ * If everything matches, then we spend almost all our time in rs_mdfour64 and
+ * rs_weak_sum, which is unavoidable and therefore a good profile.
*
* If nothing matches, it is not so good.
*
@@ -61,36 +58,34 @@
*
* The following is based entirely on pysync. It is much cleaner than the
* previous incarnation of this code. It is slightly complicated because in
- * this case the output can block, so the main delta loop needs to stop
- * when this happens.
+ * this case the output can block, so the main delta loop needs to stop when
+ * this happens.
*
* In pysync a 'last' attribute is used to hold the last miss or match for
* extending if possible. In this code, basis_len and scoop_pos are used
- * instead of 'last'. When basis_len > 0, last is a match. When basis_len =
- * 0 and scoop_pos is > 0, last is a miss. When both are 0, last is None
- * (ie, nothing).
+ * instead of 'last'. When basis_len > 0, last is a match. When basis_len = 0
+ * and scoop_pos is > 0, last is a miss. When both are 0, last is None (ie,
+ * nothing).
*
- * Pysync is also slightly different in that a 'flush' method is available
- * to force output of accumulated data. This 'flush' is use to finalise
- * delta calculation. In librsync input is terminated with an eof flag on
- * the input stream. I have structured this code similar to pysync with a
- * seperate flush function that is used when eof is reached. This allows
- * for a flush style API if one is ever needed. Note that flush in pysync
- * can be used for more than just terminating delta calculation, so a flush
- * based API can in some ways be more flexible...
+ * Pysync is also slightly different in that a 'flush' method is available to
+ * force output of accumulated data. This 'flush' is use to finalise delta
+ * calculation. In librsync input is terminated with an eof flag on the input
+ * stream. I have structured this code similar to pysync with a seperate flush
+ * function that is used when eof is reached. This allows for a flush style API
+ * if one is ever needed. Note that flush in pysync can be used for more than
+ * just terminating delta calculation, so a flush based API can in some ways be
+ * more flexible...
*
- * The input data is first scanned, then processed. Scanning identifies
- * input data as misses or matches, and emits the instruction stream.
- * Processing the data consumes it off the input scoop and outputs the
- * processed miss data into the tube.
+ * The input data is first scanned, then processed. Scanning identifies input
+ * data as misses or matches, and emits the instruction stream. Processing the
+ * data consumes it off the input scoop and outputs the processed miss data
+ * into the tube.
*
- * The scoop contains all data yet to be processed. The scoop_pos is an
- * index into the scoop that indicates the point scanned to. As data is
- * scanned, scoop_pos is incremented. As data is processed, it is removed
- * from the scoop and scoop_pos adjusted. Everything gets complicated
- * because the tube can block. When the tube is blocked, no data can be
- * processed.
- */
+ * The scoop contains all data yet to be processed. The scoop_pos is an index
+ * into the scoop that indicates the point scanned to. As data is scanned,
+ * scoop_pos is incremented. As data is processed, it is removed from the scoop
+ * and scoop_pos adjusted. Everything gets complicated because the tube can
+ * block. When the tube is blocked, no data can be processed. */
#include "config.h"
@@ -114,8 +109,10 @@ static rs_result rs_delta_s_scan(rs_job_t *job);
static rs_result rs_delta_s_flush(rs_job_t *job);
static rs_result rs_delta_s_end(rs_job_t *job);
static inline void rs_getinput(rs_job_t *job);
-static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos, size_t *match_len);
-static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos, size_t match_len);
+static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos,
+ size_t *match_len);
+static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos,
+ size_t match_len);
static inline rs_result rs_appendmiss(rs_job_t *job, size_t miss_len);
static inline rs_result rs_appendflush(rs_job_t *job);
static inline rs_result rs_processmatch(rs_job_t *job);
@@ -123,50 +120,53 @@ static inline rs_result rs_processmiss(rs_job_t *job);
/** Get a block of data if possible, and see if it matches.
*
- * On each call, we try to process all of the input data available on the
- * scoop and input buffer. */
+ * On each call, we try to process all of the input data available on the scoop
+ * and input buffer. */
static rs_result rs_delta_s_scan(rs_job_t *job)
{
- const size_t block_len = job->signature->block_len;
- rs_long_t match_pos;
- size_t match_len;
- rs_result result;
- Rollsum test;
+ const size_t block_len = job->signature->block_len;
+ rs_long_t match_pos;
+ size_t match_len;
+ rs_result result;
+ Rollsum test;
rs_job_check(job);
/* read the input into the scoop */
rs_getinput(job);
/* output any pending output from the tube */
- result=rs_tube_catchup(job);
+ result = rs_tube_catchup(job);
/* while output is not blocked and there is a block of data */
- while ((result==RS_DONE) &&
- ((job->scoop_pos + block_len) < job->scoop_avail)) {
+ while ((result == RS_DONE)
+ && ((job->scoop_pos + block_len) < job->scoop_avail)) {
/* check if this block matches */
- if (rs_findmatch(job,&match_pos,&match_len)) {
+ if (rs_findmatch(job, &match_pos, &match_len)) {
/* append the match and reset the weak_sum */
- result=rs_appendmatch(job,match_pos,match_len);
+ result = rs_appendmatch(job, match_pos, match_len);
RollsumInit(&job->weak_sum);
} else {
/* rotate the weak_sum and append the miss byte */
RollsumRotate(&job->weak_sum, job->scoop_next[job->scoop_pos],
job->scoop_next[job->scoop_pos + block_len]);
- result=rs_appendmiss(job,1);
+ result = rs_appendmiss(job, 1);
if (rs_roll_paranoia) {
RollsumInit(&test);
- RollsumUpdate(&test, job->scoop_next + job->scoop_pos, block_len);
+ RollsumUpdate(&test, job->scoop_next + job->scoop_pos,
+ block_len);
if (RollsumDigest(&test) != RollsumDigest(&job->weak_sum)) {
- rs_fatal("mismatch between rolled sum "FMT_WEAKSUM" and check "FMT_WEAKSUM"",
- RollsumDigest(&job->weak_sum), RollsumDigest(&test));
+ rs_fatal("mismatch between rolled sum " FMT_WEAKSUM
+ " and check " FMT_WEAKSUM "",
+ RollsumDigest(&job->weak_sum),
+ RollsumDigest(&test));
}
}
}
}
/* if we completed OK */
- if (result==RS_DONE) {
+ if (result == RS_DONE) {
/* if we reached eof, we can flush the last fragment */
if (job->stream->eof_in) {
- job->statefn=rs_delta_s_flush;
+ job->statefn = rs_delta_s_flush;
return RS_RUNNING;
} else {
/* we are blocked waiting for more data */
@@ -176,155 +176,153 @@ static rs_result rs_delta_s_scan(rs_job_t *job)
return result;
}
-
static rs_result rs_delta_s_flush(rs_job_t *job)
{
- rs_long_t match_pos;
- size_t match_len;
- rs_result result;
+ rs_long_t match_pos;
+ size_t match_len;
+ rs_result result;
rs_job_check(job);
/* read the input into the scoop */
rs_getinput(job);
/* output any pending output */
- result=rs_tube_catchup(job);
+ result = rs_tube_catchup(job);
/* while output is not blocked and there is any remaining data */
- while ((result==RS_DONE) && (job->scoop_pos < job->scoop_avail)) {
+ while ((result == RS_DONE) && (job->scoop_pos < job->scoop_avail)) {
/* check if this block matches */
- if (rs_findmatch(job,&match_pos,&match_len)) {
+ if (rs_findmatch(job, &match_pos, &match_len)) {
/* append the match and reset the weak_sum */
- result=rs_appendmatch(job,match_pos,match_len);
+ result = rs_appendmatch(job, match_pos, match_len);
RollsumInit(&job->weak_sum);
} else {
/* rollout from weak_sum and append the miss byte */
- RollsumRollout(&job->weak_sum,job->scoop_next[job->scoop_pos]);
- rs_trace("block reduced to "FMT_SIZE"", job->weak_sum.count);
- result=rs_appendmiss(job,1);
+ RollsumRollout(&job->weak_sum, job->scoop_next[job->scoop_pos]);
+ rs_trace("block reduced to " FMT_SIZE "", job->weak_sum.count);
+ result = rs_appendmiss(job, 1);
}
}
/* if we are not blocked, flush and set end statefn. */
- if (result==RS_DONE) {
- result=rs_appendflush(job);
- job->statefn=rs_delta_s_end;
+ if (result == RS_DONE) {
+ result = rs_appendflush(job);
+ job->statefn = rs_delta_s_end;
}
- if (result==RS_DONE) {
+ if (result == RS_DONE) {
return RS_RUNNING;
}
return result;
}
-
static rs_result rs_delta_s_end(rs_job_t *job)
{
rs_emit_end_cmd(job);
return RS_DONE;
}
-
-static inline void rs_getinput(rs_job_t *job) {
+static inline void rs_getinput(rs_job_t *job)
+{
size_t len;
- len=rs_scoop_total_avail(job);
+ len = rs_scoop_total_avail(job);
if (job->scoop_avail < len) {
- rs_scoop_input(job,len);
+ rs_scoop_input(job, len);
}
}
-
/** find a match at scoop_pos, returning the match_pos and match_len.
*
- * Note that this will calculate weak_sum if required. It will also
- * determine the match_len.
+ * Note that this will calculate weak_sum if required. It will also determine
+ * the match_len.
*
- * This routine could be modified to do xdelta style matches that
- * would extend matches past block boundaries by matching backwards and
- * forwards beyond the block boundaries. Extending backwards would require
- * decrementing scoop_pos as appropriate.
- */
-static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos, size_t *match_len) {
+ * This routine could be modified to do xdelta style matches that would extend
+ * matches past block boundaries by matching backwards and forwards beyond the
+ * block boundaries. Extending backwards would require decrementing scoop_pos
+ * as appropriate. */
+static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos,
+ size_t *match_len)
+{
const size_t block_len = job->signature->block_len;
/* calculate the weak_sum if we don't have one */
if (job->weak_sum.count == 0) {
/* set match_len to min(block_len, scan_avail) */
- *match_len=job->scoop_avail - job->scoop_pos;
+ *match_len = job->scoop_avail - job->scoop_pos;
if (*match_len > block_len) {
*match_len = block_len;
}
/* Update the weak_sum */
- RollsumUpdate(&job->weak_sum,job->scoop_next+job->scoop_pos,*match_len);
- rs_trace("calculate weak sum from scratch length "FMT_SIZE"",job->weak_sum.count);
+ RollsumUpdate(&job->weak_sum, job->scoop_next + job->scoop_pos,
+ *match_len);
+ rs_trace("calculate weak sum from scratch length " FMT_SIZE "",
+ job->weak_sum.count);
} else {
/* set the match_len to the weak_sum count */
- *match_len=job->weak_sum.count;
+ *match_len = job->weak_sum.count;
}
- *match_pos = rs_signature_find_match(job->signature,
- RollsumDigest(&job->weak_sum),
- job->scoop_next+job->scoop_pos,
- *match_len);
+ *match_pos =
+ rs_signature_find_match(job->signature, RollsumDigest(&job->weak_sum),
+ job->scoop_next + job->scoop_pos, *match_len);
return *match_pos != -1;
}
-
-/** Append a match at match_pos of length match_len to the delta, extending
- * a previous match if possible, or flushing any previous miss/match. */
-static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos, size_t match_len)
+/** Append a match at match_pos of length match_len to the delta, extending a
+ * previous match if possible, or flushing any previous miss/match. */
+static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos,
+ size_t match_len)
{
- rs_result result=RS_DONE;
+ rs_result result = RS_DONE;
/* if last was a match that can be extended, extend it */
if (job->basis_len && (job->basis_pos + job->basis_len) == match_pos) {
- job->basis_len+=match_len;
+ job->basis_len += match_len;
} else {
/* else appendflush the last value */
- result=rs_appendflush(job);
+ result = rs_appendflush(job);
/* make this the new match value */
- job->basis_pos=match_pos;
- job->basis_len=match_len;
+ job->basis_pos = match_pos;
+ job->basis_len = match_len;
}
/* increment scoop_pos to point at next unscanned data */
- job->scoop_pos+=match_len;
+ job->scoop_pos += match_len;
/* we can only process from the scoop if output is not blocked */
- if (result==RS_DONE) {
- /* process the match data off the scoop*/
- result=rs_processmatch(job);
+ if (result == RS_DONE) {
+ /* process the match data off the scoop */
+ result = rs_processmatch(job);
}
return result;
}
-
/** Append a miss of length miss_len to the delta, extending a previous miss
* if possible, or flushing any previous match.
*
- * This also breaks misses up into 32KB segments to avoid accumulating
- * too much in memory. */
+ * This also breaks misses up into 32KB segments to avoid accumulating too much
+ * in memory. */
static inline rs_result rs_appendmiss(rs_job_t *job, size_t miss_len)
{
- const size_t max_miss = 32768; /* For 0.01% 3 command bytes overhead. */
- rs_result result=RS_DONE;
+ const size_t max_miss = 32768; /* For 0.01% 3 command bytes overhead. */
+ rs_result result = RS_DONE;
/* If last was a match, or max_miss misses, appendflush it. */
if (job->basis_len || (job->scoop_pos >= max_miss)) {
- result=rs_appendflush(job);
+ result = rs_appendflush(job);
}
/* increment scoop_pos */
- job->scoop_pos+=miss_len;
+ job->scoop_pos += miss_len;
return result;
}
-
/** Flush any accumulating hit or miss, appending it to the delta. */
static inline rs_result rs_appendflush(rs_job_t *job)
{
/* if last is a match, emit it and reset last by resetting basis_len */
if (job->basis_len) {
- rs_trace("matched "FMT_LONG" bytes at "FMT_LONG"!", job->basis_len, job->basis_pos);
+ rs_trace("matched " FMT_LONG " bytes at " FMT_LONG "!", job->basis_len,
+ job->basis_pos);
rs_emit_copy_cmd(job, job->basis_pos, job->basis_len);
- job->basis_len=0;
+ job->basis_len = 0;
return rs_processmatch(job);
- /* else if last is a miss, emit and process it*/
+ /* else if last is a miss, emit and process it */
} else if (job->scoop_pos) {
- rs_trace("got "FMT_SIZE" bytes of literal data", job->scoop_pos);
+ rs_trace("got " FMT_SIZE " bytes of literal data", job->scoop_pos);
rs_emit_literal_cmd(job, job->scoop_pos);
return rs_processmiss(job);
}
@@ -332,23 +330,22 @@ static inline rs_result rs_appendflush(rs_job_t *job)
return RS_DONE;
}
-
/** Process matching data in the scoop.
*
* The scoop contains match data at scoop_next of length scoop_pos. This
- * function processes that match data, returning RS_DONE if it completes,
- * or RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset
- * to still point at the next unscanned data.
+ * function processes that match data, returning RS_DONE if it completes, or
+ * RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset to
+ * still point at the next unscanned data.
*
* This function currently just removes data from the scoop and adjusts
- * scoop_pos appropriately. In the future this could be used for something
- * like context compressing of miss data. Note that it also calls
- * rs_tube_catchup to output any pending output. */
+ * scoop_pos appropriately. In the future this could be used for something like
+ * context compressing of miss data. Note that it also calls rs_tube_catchup to
+ * output any pending output. */
static inline rs_result rs_processmatch(rs_job_t *job)
{
- job->scoop_avail-=job->scoop_pos;
- job->scoop_next+=job->scoop_pos;
- job->scoop_pos=0;
+ job->scoop_avail -= job->scoop_pos;
+ job->scoop_next += job->scoop_pos;
+ job->scoop_pos = 0;
return rs_tube_catchup(job);
}
@@ -359,31 +356,28 @@ static inline rs_result rs_processmatch(rs_job_t *job)
* RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset to
* still point at the next unscanned data.
*
- * This function uses rs_tube_copy to queue copying from the scoop into
- * output. and uses rs_tube_catchup to do the copying. This automaticly
- * removes data from the scoop, but this can block. While rs_tube_catchup
- * is blocked, scoop_pos does not point at legit data, so scanning can also
- * not proceed.
+ * This function uses rs_tube_copy to queue copying from the scoop into output.
+ * and uses rs_tube_catchup to do the copying. This automaticly removes data
+ * from the scoop, but this can block. While rs_tube_catchup is blocked,
+ * scoop_pos does not point at legit data, so scanning can also not proceed.
*
- * In the future this could do compression of miss data before outputing
- * it. */
+ * In the future this could do compression of miss data before outputing it. */
static inline rs_result rs_processmiss(rs_job_t *job)
{
rs_tube_copy(job, job->scoop_pos);
- job->scoop_pos=0;
+ job->scoop_pos = 0;
return rs_tube_catchup(job);
}
-
-/** State function that does a slack delta containing only
- * literal data to recreate the input. */
+/** State function that does a slack delta containing only literal data to
+ * recreate the input. */
static rs_result rs_delta_s_slack(rs_job_t *job)
{
- rs_buffers_t * const stream = job->stream;
+ rs_buffers_t *const stream = job->stream;
size_t avail = stream->avail_in;
if (avail) {
- rs_trace("emit slack delta for "FMT_SIZE" available bytes", avail);
+ rs_trace("emit slack delta for " FMT_SIZE " available bytes", avail);
rs_emit_literal_cmd(job, avail);
rs_tube_copy(job, avail);
return RS_RUNNING;
@@ -394,7 +388,6 @@ static rs_result rs_delta_s_slack(rs_job_t *job)
return RS_BLOCKED;
}
-
/** State function for writing out the header of the encoding job. */
static rs_result rs_delta_s_header(rs_job_t *job)
{
@@ -408,7 +401,6 @@ static rs_result rs_delta_s_header(rs_job_t *job)
return RS_RUNNING;
}
-
rs_job_t *rs_delta_begin(rs_signature_t *sig)
{
rs_job_t *job;
diff --git a/src/emit.c b/src/emit.c
index 49859a5..0060896 100644
--- a/src/emit.c
+++ b/src/emit.c
@@ -21,9 +21,8 @@
/** \file emit.c encoding output routines.
*
- * \todo Pluggable encoding formats: gdiff-style, rsync 24, ed (text),
- * Delta HTTP.
- */
+ * \todo Pluggable encoding formats: gdiff-style, rsync 24, ed (text), Delta
+ * HTTP. */
#include "config.h"
@@ -40,20 +39,15 @@
#include "sumset.h"
#include "job.h"
-
/** Write the magic for the start of a delta. */
-void
-rs_emit_delta_header(rs_job_t *job)
+void rs_emit_delta_header(rs_job_t *job)
{
rs_trace("emit DELTA magic");
rs_squirt_n4(job, RS_DELTA_MAGIC);
}
-
-
/** Write a LITERAL command. */
-void
-rs_emit_literal_cmd(rs_job_t *job, int len)
+void rs_emit_literal_cmd(rs_job_t *job, int len)
{
int cmd;
int param_len = rs_int_len(len);
@@ -76,18 +70,16 @@ rs_emit_literal_cmd(rs_job_t *job, int len)
job->stats.lit_cmdbytes += 1 + param_len;
}
-
/** Write a COPY command for given offset and length.
*
- * There is a choice of variable-length encodings, depending on the
- * size of representation for the parameters. */
-void
-rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
+ * There is a choice of variable-length encodings, depending on the size of
+ * representation for the parameters. */
+void rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
{
- int cmd;
- rs_stats_t *stats = &job->stats;
+ int cmd;
+ rs_stats_t *stats = &job->stats;
const int where_bytes = rs_int_len(where);
- const int len_bytes = rs_int_len(len);
+ const int len_bytes = rs_int_len(len);
/* Commands ascend (1,1), (1,2), ... (8, 8) */
if (where_bytes == 8)
@@ -101,8 +93,7 @@ rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
cmd = RS_OP_COPY_N1_N1;
}
- if (len_bytes == 1)
- ;
+ if (len_bytes == 1) ;
else if (len_bytes == 2)
cmd += 1;
else if (len_bytes == 4)
@@ -112,8 +103,8 @@ rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
cmd += 3;
}
- rs_trace("emit COPY_N%d_N%d(where="FMT_LONG", len="FMT_LONG"), cmd_byte=%#04x",
- where_bytes, len_bytes, where, len, cmd);
+ rs_trace("emit COPY_N%d_N%d(where=" FMT_LONG ", len=" FMT_LONG
+ "), cmd_byte=%#04x", where_bytes, len_bytes, where, len, cmd);
rs_squirt_byte(job, cmd);
rs_squirt_netint(job, where, where_bytes);
rs_squirt_netint(job, len, len_bytes);
@@ -125,10 +116,8 @@ rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
/* \todo All the stats */
}
-
/** Write an END command. */
-void
-rs_emit_end_cmd(rs_job_t *job)
+void rs_emit_end_cmd(rs_job_t *job)
{
int cmd = RS_OP_END;
diff --git a/src/fileutil.c b/src/fileutil.c
index 2eb7fae..d394a46 100644
--- a/src/fileutil.c
+++ b/src/fileutil.c
@@ -25,17 +25,17 @@
#include <assert.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+# include <fcntl.h>
#endif
#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
+# include <sys/file.h>
#endif
#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
+# include <sys/stat.h>
#endif
#include <string.h>
#include <errno.h>
@@ -44,7 +44,6 @@
#include "fileutil.h"
#include "trace.h"
-
/* Use fseeko64, _fseeki64, or fseeko for long files if they exist. */
#if defined(HAVE_FSEEKO64) && (SIZEOF_OFF_T < 8)
# define fopen(f, m) fopen64((f), (m))
@@ -74,58 +73,56 @@
# define fileno(f) _fileno((f))
#endif
-
/** Open a file with special handling for '-' or unspecified filenames.
*
* \param filename - The filename to open.
- *
+ *
* \param mode - fopen style mode string.
- *
- * \param force - bool to force overwriting of existing files.
- */
+ *
+ * \param force - bool to force overwriting of existing files. */
FILE *rs_file_open(char const *filename, char const *mode, int force)
{
- FILE *f;
- int is_write;
+ FILE *f;
+ int is_write;
is_write = mode[0] == 'w';
- if (!filename || !strcmp("-", filename)) {
- if (is_write) {
+ if (!filename || !strcmp("-", filename)) {
+ if (is_write) {
#if _WIN32
- _setmode(_fileno(stdout), _O_BINARY);
+ _setmode(_fileno(stdout), _O_BINARY);
#endif
- return stdout;
- } else {
+ return stdout;
+ } else {
#if _WIN32
- _setmode(_fileno(stdin), _O_BINARY);
+ _setmode(_fileno(stdin), _O_BINARY);
#endif
- return stdin;
- }
+ return stdin;
+ }
}
if (!force && is_write) {
- if ((f = fopen(filename, "rb"))) {
- // File exists
- rs_error("File exists \"%s\", aborting!", filename);
- fclose(f);
- exit(RS_IO_ERROR);
- }
+ if ((f = fopen(filename, "rb"))) {
+ // File exists
+ rs_error("File exists \"%s\", aborting!", filename);
+ fclose(f);
+ exit(RS_IO_ERROR);
+ }
}
if (!(f = fopen(filename, mode))) {
- rs_error("Error opening \"%s\" for %s: %s", filename,
- is_write ? "write" : "read",
- strerror(errno));
- exit(RS_IO_ERROR);
+ rs_error("Error opening \"%s\" for %s: %s", filename,
+ is_write ? "write" : "read", strerror(errno));
+ exit(RS_IO_ERROR);
}
return f;
}
-int rs_file_close(FILE * f)
+int rs_file_close(FILE *f)
{
- if ((f == stdin) || (f == stdout)) return 0;
+ if ((f == stdin) || (f == stdout))
+ return 0;
return fclose(f);
}
@@ -139,8 +136,8 @@ void rs_get_filesize(FILE *f, rs_long_t *size)
rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf)
{
- int got;
- FILE *f = (FILE *) arg;
+ int got;
+ FILE *f = (FILE *)arg;
if (fseek(f, pos, SEEK_SET)) {
rs_error("seek failed: %s", strerror(errno));
diff --git a/src/fileutil.h b/src/fileutil.h
index dfea54e..e0beb03 100644
--- a/src/fileutil.h
+++ b/src/fileutil.h
@@ -1,24 +1,24 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- *
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-FILE * rs_file_open(char const *filename, char const * mode, int force);
-int rs_file_close(FILE * file);
+FILE *rs_file_open(char const *filename, char const *mode, int force);
+int rs_file_close(FILE *file);
void rs_get_filesize(FILE *f, rs_long_t *size);
diff --git a/src/hashtable.h b/src/hashtable.h
index f2f6480..f1b0b27 100644
--- a/src/hashtable.h
+++ b/src/hashtable.h
@@ -18,38 +18,35 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _HASHTABLE_H_
-#define _HASHTABLE_H_
+# define _HASHTABLE_H_
-#include <assert.h>
-#include <stdlib.h>
+# include <assert.h>
+# include <stdlib.h>
-/** \file hashtable.h
- * A generic open addressing hashtable.
+/** \file hashtable.h A generic open addressing hashtable.
*
- * This is a minimal hashtable containing pointers to arbitrary
- * entries with configurable hashtable size and support for custom
- * hash() and cmp() methods. The cmp() method can either be a simple
- * comparison between two keys, or can be against a special match
- * object containing additional mutable state. This allows for things
- * like deferred and cached evaluation of costly comparison data. The
- * hash() function doesn't need to avoid clustering behaviour.
+ * This is a minimal hashtable containing pointers to arbitrary entries with
+ * configurable hashtable size and support for custom hash() and cmp() methods.
+ * The cmp() method can either be a simple comparison between two keys, or can
+ * be against a special match object containing additional mutable state. This
+ * allows for things like deferred and cached evaluation of costly comparison
+ * data. The hash() function doesn't need to avoid clustering behaviour.
*
* It uses open addressing with quadratic probing for collisions. The
- * MurmurHash3 finalization function is used on the hash() output to
- * avoid clustering. There is no support for removing entries, only
- * adding them. Multiple entries with the same key can be added, and
- * you can use a fancy cmp() function to find particular entries by
- * more than just their key. There is an iterator for iterating
- * through all entries in the hashtable. There are optional
- * hashtable_find() find/match/hashcmp/entrycmp stats counters that
+ * MurmurHash3 finalization function is used on the hash() output to avoid
+ * clustering. There is no support for removing entries, only adding them.
+ * Multiple entries with the same key can be added, and you can use a fancy
+ * cmp() function to find particular entries by more than just their key. There
+ * is an iterator for iterating through all entries in the hashtable. There are
+ * optional hashtable_find() find/match/hashcmp/entrycmp stats counters that
* can be disabled by defining HASHTABLE_NSTATS.
*
- * The types and methods of the hashtable and its contents are
- * specified by using \#define parameters set to their basenames (the
- * prefixes for the *_t type and *_func() methods) before doing
- * \#include "hashtable.h". This produces static inline type-safe
- * methods that are either application optimized for speed or
- * wrappers around void* implementation methods for compactness.
+ * The types and methods of the hashtable and its contents are specified by
+ * using \#define parameters set to their basenames (the prefixes for the *_t
+ * type and *_func() methods) before doing \#include "hashtable.h". This
+ * produces static inline type-safe methods that are either application
+ * optimized for speed or wrappers around void* implementation methods for
+ * compactness.
*
* \param ENTRY - the entry type basename.
*
@@ -93,11 +90,11 @@
* myentry_hashtable_free(t);
* \endcode
*
- * The mykey_hash() and mykey_cmp() fuctions will typically take pointers
- * to mykey/myentry instances the same as the pointers stored in the
- * hashtable. However it is also possible for them to take "match
- * objects" that are a "subclass" of the entry type that contain
- * additional state for complicated comparision operations.
+ * The mykey_hash() and mykey_cmp() fuctions will typically take pointers to
+ * mykey/myentry instances the same as the pointers stored in the hashtable.
+ * However it is also possible for them to take "match objects" that are a
+ * "subclass" of the entry type that contain additional state for complicated
+ * comparision operations.
*
* Example: \code
* typedef struct mymatch {
@@ -120,23 +117,22 @@
* e = myentry_hashtable_find(t, &m);
* \endcode
*
- * The mymatch_cmp() function is only called for finding hashtable
- * entries and can mutate the mymatch_t object for doing things like
- * deferred and cached evaluation of expensive match data. It can
- * also access the whole myentry_t object to match against more than
- * just the key. */
+ * The mymatch_cmp() function is only called for finding hashtable entries and
+ * can mutate the mymatch_t object for doing things like deferred and cached
+ * evaluation of expensive match data. It can also access the whole myentry_t
+ * object to match against more than just the key. */
/** The hashtable type. */
typedef struct hashtable {
int size; /**< Size of allocated hashtable. */
int count; /**< Number of entries in hashtable. */
-#ifndef HASHTABLE_NSTATS
+# ifndef HASHTABLE_NSTATS
/* The following are for accumulating hashtable_find() stats. */
long find_count; /**< The count of finds tried. */
long match_count; /**< The count of matches found. */
long hashcmp_count; /**< The count of hash compares done. */
long entrycmp_count; /**< The count of entry compares done. */
-#endif
+# endif
void **etable; /**< Table of pointers to entries. */
unsigned ktable[]; /**< Table of hash keys. */
} hashtable_t;
@@ -169,72 +165,69 @@ static inline unsigned mix32(unsigned int h)
/* If ENTRY is defined, define type-dependent static inline methods. */
#ifdef ENTRY
-#define _JOIN2(x, y) x##y
-#define _JOIN(x, y) _JOIN2(x, y)
+# define _JOIN2(x, y) x##y
+# define _JOIN(x, y) _JOIN2(x, y)
-#ifndef KEY
-#define KEY ENTRY
-#endif
+# ifndef KEY
+# define KEY ENTRY
+# endif
-#ifndef MATCH
-#define MATCH KEY
-#endif
+# ifndef MATCH
+# define MATCH KEY
+# endif
-#ifndef NAME
-#define NAME _JOIN(ENTRY, _hashtable)
-#endif
+# ifndef NAME
+# define NAME _JOIN(ENTRY, _hashtable)
+# endif
-#define ENTRY_T _JOIN(ENTRY, _t) /**< The entry type. */
-#define KEY_T _JOIN(KEY, _t) /**< The key type. */
-#define MATCH_T _JOIN(MATCH, _t) /**< The match type. */
+# define ENTRY_T _JOIN(ENTRY, _t) /**< The entry type. */
+# define KEY_T _JOIN(KEY, _t) /**< The key type. */
+# define MATCH_T _JOIN(MATCH, _t) /**< The match type. */
/** The key hash(k) method. */
-#define KEY_HASH(k) _JOIN(KEY, _hash)(k)
+# define KEY_HASH(k) _JOIN(KEY, _hash)(k)
/** The match cmp(m, e) method. */
-#define MATCH_CMP(m, e) _JOIN(MATCH, _cmp)(m, e)
-#define _FUNC(f) _JOIN(NAME, f)
+# define MATCH_CMP(m, e) _JOIN(MATCH, _cmp)(m, e)
+# define _FUNC(f) _JOIN(NAME, f)
/* Loop macro for probing table t for key k, setting hk to the hash for k
- reserving zero for empty buckets, and iterating with index i and entry
- hash h, terminating at an empty bucket. */
-#define _for_probe(t, k, hk, i, h) \
+ reserving zero for empty buckets, and iterating with index i and entry hash
+ h, terminating at an empty bucket. */
+# define _for_probe(t, k, hk, i, h) \
const unsigned mask = t->size - 1;\
unsigned hk = KEY_HASH((KEY_T *)k), i, s, h;\
hk = hk ? hk : -1;\
for (i = mix32(hk) & mask, s = 0; (h = t->ktable[i]); i = (i + ++s) & mask)
/* Conditional macro for incrementing stats counters. */
-#ifndef HASHTABLE_NSTATS
-#define _stats_inc(c) (c++)
-#else
-#define _stats_inc(c)
-#endif
+# ifndef HASHTABLE_NSTATS
+# define _stats_inc(c) (c++)
+# else
+# define _stats_inc(c)
+# endif
/** Allocate and initialize a hashtable instance.
*
- * The provided size is used as an indication of the number of
- * entries you wish to add, but the allocated size will probably be
- * larger depending on the implementation to enable optimisations or
- * avoid degraded performance. It may be possible to fill the table
- * beyond the requested size, but performance can start to degrade
- * badly if it is over filled.
+ * The provided size is used as an indication of the number of entries you wish
+ * to add, but the allocated size will probably be larger depending on the
+ * implementation to enable optimisations or avoid degraded performance. It may
+ * be possible to fill the table beyond the requested size, but performance can
+ * start to degrade badly if it is over filled.
*
* \param size - The desired minimum size of the hash table.
*
* \return The initialized hashtable instance or NULL if it failed. */
-static inline hashtable_t *_FUNC(_new)(int size)
-{
+static inline hashtable_t *_FUNC(_new) (int size) {
return _hashtable_new(size);
}
/** Destroy and free a hashtable instance.
*
* This will free the hashtable, but will not free the entries in the
- * hashtable. If you want to free the entries too, use a hashtable
- * iterator to free the the entries first.
+ * hashtable. If you want to free the entries too, use a hashtable iterator to
+ * free the the entries first.
*
* \param *t - The hashtable to destroy and free. */
-static inline void _FUNC(_free)(hashtable_t *t)
-{
+static inline void _FUNC(_free) (hashtable_t *t) {
_hashtable_free(t);
}
@@ -243,27 +236,24 @@ static inline void _FUNC(_free)(hashtable_t *t)
* This will reset all the stats counters for the hashtable,
*
* \param *t - The hashtable to initializ stats for. */
-static inline void _FUNC(_stats_init)(hashtable_t *t)
-{
-#ifndef HASHTABLE_NSTATS
+static inline void _FUNC(_stats_init) (hashtable_t *t) {
+# ifndef HASHTABLE_NSTATS
t->find_count = t->match_count = t->hashcmp_count = t->entrycmp_count = 0;
-#endif
+# endif
}
/** Add an entry to a hashtable.
*
* This doesn't use MATCH_CMP() or do any checks for existing copies or
* instances, so it will add duplicates. If you want to avoid adding
- * duplicates, use hashtable_find() to check for existing entries
- * first.
+ * duplicates, use hashtable_find() to check for existing entries first.
*
* \param *t - The hashtable to add to.
*
* \param *e - The entry object to add.
*
* \return The added entry, or NULL if the table is full. */
-static inline ENTRY_T *_FUNC(_add)(hashtable_t *t, ENTRY_T *e)
-{
+static inline ENTRY_T *_FUNC(_add) (hashtable_t *t, ENTRY_T * e) {
assert(e != NULL);
if (t->count + 1 == t->size)
return NULL;
@@ -275,16 +265,15 @@ static inline ENTRY_T *_FUNC(_add)(hashtable_t *t, ENTRY_T *e)
/** Find an entry in a hashtable.
*
- * Uses MATCH_CMP() to find the first matching entry in the table in the
- * same hash() bucket.
+ * Uses MATCH_CMP() to find the first matching entry in the table in the same
+ * hash() bucket.
*
* \param *t - The hashtable to search.
*
* \param *m - The key or match object to search for.
*
* \return The first found entry, or NULL if nothing was found. */
-static inline ENTRY_T *_FUNC(_find)(hashtable_t *t, MATCH_T *m)
-{
+static inline ENTRY_T *_FUNC(_find) (hashtable_t *t, MATCH_T * m) {
assert(m != NULL);
ENTRY_T *e;
@@ -304,8 +293,8 @@ static inline ENTRY_T *_FUNC(_find)(hashtable_t *t, MATCH_T *m)
/** Initialize a hashtable_iter_t and return the first entry.
*
- * This works together with hashtable_next() for iterating through
- * all entries in a hashtable.
+ * This works together with hashtable_next() for iterating through all entries
+ * in a hashtable.
*
* Example: \code
* for (e = hashtable_iter(&i, t); e != NULL; e = hashtable_next(&i))
@@ -317,8 +306,7 @@ static inline ENTRY_T *_FUNC(_find)(hashtable_t *t, MATCH_T *m)
* \param *t - the hashtable to iterate over.
*
* \return The first entry or NULL if the hashtable is empty. */
-static inline ENTRY_T *_FUNC(_iter)(hashtable_iter_t *i, hashtable_t *t)
-{
+static inline ENTRY_T *_FUNC(_iter) (hashtable_iter_t *i, hashtable_t *t) {
return _hashtable_iter(i, t);
}
@@ -327,19 +315,18 @@ static inline ENTRY_T *_FUNC(_iter)(hashtable_iter_t *i, hashtable_t *t)
* \param *i - the hashtable iterator to use.
*
* \return The next entry or NULL if the iterator is finished. */
-static inline ENTRY_T *_FUNC(_next)(hashtable_iter_t *i)
-{
+static inline ENTRY_T *_FUNC(_next) (hashtable_iter_t *i) {
return _hashtable_next(i);
}
-#undef ENTRY
-#undef KEY
-#undef MATCH
-#undef NAME
-#undef ENTRY_T
-#undef KEY_T
-#undef MATCH_T
-#undef KEY_HASH
-#undef MATCH_CMP
-#undef _FUNC
+# undef ENTRY
+# undef KEY
+# undef MATCH
+# undef NAME
+# undef ENTRY_T
+# undef KEY_T
+# undef MATCH_T
+# undef KEY_HASH
+# undef MATCH_CMP
+# undef _FUNC
#endif /* ENTRY */
diff --git a/src/hex.c b/src/hex.c
index 88b58cb..220598b 100644
--- a/src/hex.c
+++ b/src/hex.c
@@ -1,17 +1,17 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -22,24 +22,22 @@
#include <assert.h>
#include <sys/types.h>
#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
+# include <inttypes.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include "librsync.h"
-
-void
-rs_hexify(char *to_buf, void const *from, int from_len)
+void rs_hexify(char *to_buf, void const *from, int from_len)
{
static const char hex_chars[] = "0123456789abcdef";
- unsigned char const *from_buf = (unsigned char const *) from;
+ unsigned char const *from_buf = (unsigned char const *)from;
while (from_len-- > 0) {
- *(to_buf++) = hex_chars[((*from_buf) >> 4) & 0xf];
- *(to_buf++) = hex_chars[(*from_buf) & 0xf];
- from_buf++;
+ *(to_buf++) = hex_chars[((*from_buf) >> 4) & 0xf];
+ *(to_buf++) = hex_chars[(*from_buf) & 0xf];
+ from_buf++;
}
*to_buf = 0;
diff --git a/src/isprefix.c b/src/isprefix.c
index a2f700c..e0fd2b0 100644
--- a/src/isprefix.c
+++ b/src/isprefix.c
@@ -1,36 +1,33 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
* librsync -- dynamic caching and delta update in HTTP
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
#include "isprefix.h"
-/**
- * Return true if TIP is a prefix of ICEBERG.
- */
-int
-isprefix(char const *tip, char const *iceberg)
+/** Return true if TIP is a prefix of ICEBERG. */
+int isprefix(char const *tip, char const *iceberg)
{
while (*tip) {
- if (*tip != *iceberg)
- return 0;
- tip++; iceberg++;
+ if (*tip != *iceberg)
+ return 0;
+ tip++;
+ iceberg++;
}
return 1;
diff --git a/src/isprefix.h b/src/isprefix.h
index 0c0a225..e24b193 100644
--- a/src/isprefix.h
+++ b/src/isprefix.h
@@ -1,23 +1,22 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
* librsync -- dynamic caching and delta update in HTTP
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
/** Return true if TIP is a prefix of ICEBERG. */
int isprefix(char const *tip, char const *iceberg);
diff --git a/src/job.c b/src/job.c
index 65a79d1..f1a9650 100644
--- a/src/job.c
+++ b/src/job.c
@@ -27,14 +27,10 @@
/** \file job.c Generic state-machine interface.
*
- * The point of this is
- * that we need to be able to suspend and resume processing at any
- * point at which the buffers may block.
+ * The point of this is that we need to be able to suspend and resume
+ * processing at any point at which the buffers may block.
*
- * \sa \ref api_streaming
- * \sa rs_job_iter()
- * \sa ::rs_job
- */
+ * \sa \ref api_streaming \sa rs_job_iter() \sa ::rs_job */
#include "config.h"
@@ -50,11 +46,9 @@
#include "job.h"
#include "trace.h"
-
static rs_result rs_job_work(rs_job_t *job, rs_buffers_t *buffers);
-
-rs_job_t * rs_job_new(char const *job_name, rs_result (*statefn)(rs_job_t *))
+rs_job_t *rs_job_new(char const *job_name, rs_result (*statefn) (rs_job_t *))
{
rs_job_t *job;
@@ -72,19 +66,17 @@ rs_job_t * rs_job_new(char const *job_name, rs_result (*statefn)(rs_job_t *))
return job;
}
-
rs_result rs_job_free(rs_job_t *job)
{
free(job->scoop_buf);
if (job->job_owns_sig)
- rs_free_sumset(job->signature);
+ rs_free_sumset(job->signature);
rs_bzero(job, sizeof *job);
free(job);
return RS_DONE;
}
-
static rs_result rs_job_complete(rs_job_t *job, rs_result result)
{
rs_job_check(job);
@@ -101,30 +93,29 @@ static rs_result rs_job_complete(rs_job_t *job, rs_result result)
return result;
}
-
rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers)
{
- rs_result result;
- size_t orig_in, orig_out;
+ rs_result result;
+ size_t orig_in, orig_out;
rs_job_check(job);
assert(buffers);
- orig_in = buffers->avail_in;
+ orig_in = buffers->avail_in;
orig_out = buffers->avail_out;
result = rs_job_work(job, buffers);
if (result == RS_BLOCKED || result == RS_DONE)
- if ((orig_in == buffers->avail_in) && (orig_out == buffers->avail_out)
+ if ((orig_in == buffers->avail_in) && (orig_out == buffers->avail_out)
&& orig_in && orig_out) {
- rs_error("internal error: job made no progress "
- "[orig_in="FMT_SIZE", orig_out="FMT_SIZE", final_in="FMT_SIZE", final_out="FMT_SIZE"]",
- orig_in, orig_out, buffers->avail_in, buffers->avail_out);
+ rs_error("internal error: job made no progress " "[orig_in="
+ FMT_SIZE ", orig_out=" FMT_SIZE ", final_in=" FMT_SIZE
+ ", final_out=" FMT_SIZE "]", orig_in, orig_out,
+ buffers->avail_in, buffers->avail_out);
return RS_INTERNAL_ERROR;
}
return result;
}
-
static rs_result rs_job_work(rs_job_t *job, rs_buffers_t *buffers)
{
rs_result result;
@@ -151,27 +142,20 @@ static rs_result rs_job_work(rs_job_t *job, rs_buffers_t *buffers)
}
}
-
-const rs_stats_t *
-rs_job_statistics(rs_job_t *job)
+const rs_stats_t *rs_job_statistics(rs_job_t *job)
{
return &job->stats;
}
-
-int
-rs_job_input_is_ending(rs_job_t *job)
+int rs_job_input_is_ending(rs_job_t *job)
{
return job->stream->eof_in;
}
-
-rs_result
-rs_job_drive(rs_job_t *job, rs_buffers_t *buf,
- rs_driven_cb in_cb, void *in_opaque,
- rs_driven_cb out_cb, void *out_opaque)
+rs_result rs_job_drive(rs_job_t *job, rs_buffers_t *buf, rs_driven_cb in_cb,
+ void *in_opaque, rs_driven_cb out_cb, void *out_opaque)
{
- rs_result result, iores;
+ rs_result result, iores;
rs_bzero(buf, sizeof *buf);
@@ -183,11 +167,11 @@ rs_job_drive(rs_job_t *job, rs_buffers_t *buf,
}
result = rs_job_iter(job, buf);
- if (result != RS_DONE && result != RS_BLOCKED)
+ if (result != RS_DONE && result != RS_BLOCKED)
return result;
if (out_cb) {
- iores = (out_cb)(job, buf, out_opaque);
+ iores = (out_cb) (job, buf, out_opaque);
if (iores != RS_DONE)
return iores;
}
diff --git a/src/job.h b/src/job.h
index d3c7b6b..d0206c5 100644
--- a/src/job.h
+++ b/src/job.h
@@ -22,88 +22,82 @@
#include "mdfour.h"
#include "rollsum.h"
-/** \struct rs_job
- * The contents of this structure are private.
- */
+/** \struct rs_job The contents of this structure are private. */
struct rs_job {
- int dogtag;
+ int dogtag;
/** Human-readable job operation name. */
- const char *job_name;
+ const char *job_name;
rs_buffers_t *stream;
/** Callback for each processing step. */
- rs_result (*statefn)(rs_job_t *);
+ rs_result (*statefn) (rs_job_t *);
/** Final result of processing job. Used by rs_job_s_failed(). */
rs_result final_result;
- /* Arguments for initializing the signature used by mksum.c and
- * readsums.c. */
- int sig_magic;
- int sig_block_len;
- int sig_strong_len;
+ /* Arguments for initializing the signature used by mksum.c and readsums.c.
+ */
+ int sig_magic;
+ int sig_block_len;
+ int sig_strong_len;
- /** The size of the signature file if available. Used by loadsums.c
- * when initializing the signature to preallocate memory. */
- rs_long_t sig_fsize;
+ /** The size of the signature file if available. Used by loadsums.c when
+ * initializing the signature to preallocate memory. */
+ rs_long_t sig_fsize;
/** Pointer to the signature that's being used by the operation. */
- rs_signature_t *signature;
+ rs_signature_t *signature;
/** Flag indicating signature should be destroyed with the job. */
- int job_owns_sig;
+ int job_owns_sig;
/** Command byte currently being processed, if any. */
- unsigned char op;
+ unsigned char op;
/** The weak signature digest used by readsums.c */
- rs_weak_sum_t weak_sig;
+ rs_weak_sum_t weak_sig;
/** The rollsum weak signature accumulator used by delta.c */
- Rollsum weak_sum;
+ Rollsum weak_sum;
/** Lengths of expected parameters. */
- rs_long_t param1, param2;
+ rs_long_t param1, param2;
struct rs_prototab_ent const *cmd;
- rs_mdfour_t output_md4;
+ rs_mdfour_t output_md4;
/** Encoding statistics. */
- rs_stats_t stats;
-
- /**
- * Buffer of data in the scoop. Allocation is
- * scoop_buf[0..scoop_alloc], and scoop_next[0..scoop_avail] contains
- * data yet to be processed. scoop_next[scoop_pos..scoop_avail] is the
- * data yet to be scanned. */
- rs_byte_t *scoop_buf; /* the allocation pointer */
- rs_byte_t *scoop_next; /* the data pointer */
- size_t scoop_alloc; /* the allocation size */
- size_t scoop_avail; /* the data size */
- size_t scoop_pos; /* the scan position */
-
- /** If USED is >0, then buf contains that much write data to
- * be sent out. */
- rs_byte_t write_buf[36];
- int write_len;
-
- /** If \p copy_len is >0, then that much data should be copied
- * through from the input. */
- rs_long_t copy_len;
+ rs_stats_t stats;
+
+ /** Buffer of data in the scoop. Allocation is scoop_buf[0..scoop_alloc],
+ * and scoop_next[0..scoop_avail] contains data yet to be processed.
+ * scoop_next[scoop_pos..scoop_avail] is the data yet to be scanned. */
+ rs_byte_t *scoop_buf; /* the allocation pointer */
+ rs_byte_t *scoop_next; /* the data pointer */
+ size_t scoop_alloc; /* the allocation size */
+ size_t scoop_avail; /* the data size */
+ size_t scoop_pos; /* the scan position */
+
+ /** If USED is >0, then buf contains that much write data to be sent out. */
+ rs_byte_t write_buf[36];
+ int write_len;
+
+ /** If \p copy_len is >0, then that much data should be copied through
+ * from the input. */
+ rs_long_t copy_len;
/** Copy from the basis position. */
- rs_long_t basis_pos, basis_len;
+ rs_long_t basis_pos, basis_len;
/** Callback used to copy data from the basis into the output. */
- rs_copy_cb *copy_cb;
- void *copy_arg;
+ rs_copy_cb *copy_cb;
+ void *copy_arg;
};
-
-rs_job_t * rs_job_new(const char *, rs_result (*statefn)(rs_job_t *));
+rs_job_t *rs_job_new(const char *, rs_result (*statefn) (rs_job_t *));
int rs_job_input_is_ending(rs_job_t *job);
diff --git a/src/librsync.h b/src/librsync.h
index b8d87c9..933994b 100644
--- a/src/librsync.h
+++ b/src/librsync.h
@@ -30,16 +30,16 @@
/** \file librsync.h Public header for librsync. */
#ifndef _RSYNC_H
-#define _RSYNC_H
+# define _RSYNC_H
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <time.h>
+# include <sys/types.h>
+# include <stdio.h>
+# include <stdint.h>
+# include <time.h>
-#ifdef __cplusplus
+# ifdef __cplusplus
extern "C" {
-#endif
+# endif
/** Library version string.
*
@@ -71,47 +71,43 @@ typedef enum {
* At present, there's only one delta format.
*
* The four-byte literal \c "rs\x026". */
- RS_DELTA_MAGIC = 0x72730236,
+ RS_DELTA_MAGIC = 0x72730236,
/** A signature file with MD4 signatures.
*
- * Backward compatible with
- * librsync < 1.0, but strongly deprecated because it creates a security
- * vulnerability on files containing partly untrusted data. See
- * <https://github.com/librsync/librsync/issues/5>.
+ * Backward compatible with librsync < 1.0, but strongly deprecated because
+ * it creates a security vulnerability on files containing partly untrusted
+ * data. See <https://github.com/librsync/librsync/issues/5>.
*
* The four-byte literal \c "rs\x016".
*
* \sa rs_sig_begin() */
- RS_MD4_SIG_MAGIC = 0x72730136,
+ RS_MD4_SIG_MAGIC = 0x72730136,
/** A signature file using the BLAKE2 hash. Supported from librsync 1.0.
*
* The four-byte literal \c "rs\x017".
*
* \sa rs_sig_begin() */
- RS_BLAKE2_SIG_MAGIC = 0x72730137
+ RS_BLAKE2_SIG_MAGIC = 0x72730137
} rs_magic_number;
-
/** Log severity levels.
*
* These are the same as syslog, at least in glibc.
*
- * \sa rs_trace_set_level()
- * \sa \ref api_trace */
+ * \sa rs_trace_set_level() \sa \ref api_trace */
typedef enum {
- RS_LOG_EMERG = 0, /**< System is unusable */
- RS_LOG_ALERT = 1, /**< Action must be taken immediately */
- RS_LOG_CRIT = 2, /**< Critical conditions */
- RS_LOG_ERR = 3, /**< Error conditions */
- RS_LOG_WARNING = 4, /**< Warning conditions */
- RS_LOG_NOTICE = 5, /**< Normal but significant condition */
- RS_LOG_INFO = 6, /**< Informational */
- RS_LOG_DEBUG = 7 /**< Debug-level messages */
+ RS_LOG_EMERG = 0, /**< System is unusable */
+ RS_LOG_ALERT = 1, /**< Action must be taken immediately */
+ RS_LOG_CRIT = 2, /**< Critical conditions */
+ RS_LOG_ERR = 3, /**< Error conditions */
+ RS_LOG_WARNING = 4, /**< Warning conditions */
+ RS_LOG_NOTICE = 5, /**< Normal but significant condition */
+ RS_LOG_INFO = 6, /**< Informational */
+ RS_LOG_DEBUG = 7 /**< Debug-level messages */
} rs_loglevel;
-
/** \typedef rs_trace_fn_t Callback to write out log messages.
*
* \param level a syslog level.
@@ -119,39 +115,37 @@ typedef enum {
* \param msg message to be logged.
*
* \sa \ref api_trace */
-typedef void rs_trace_fn_t(rs_loglevel level, char const *msg);
+typedef void rs_trace_fn_t(rs_loglevel level, char const *msg);
/** Set the least important message severity that will be output.
*
* \sa \ref api_trace */
-void rs_trace_set_level(rs_loglevel level);
+void rs_trace_set_level(rs_loglevel level);
/** Set trace callback.
*
* \sa \ref api_trace */
-void rs_trace_to(rs_trace_fn_t *);
+void rs_trace_to(rs_trace_fn_t *);
/** Default trace callback that writes to stderr.
*
* Implements ::rs_trace_fn_t, and may be passed to rs_trace_to().
*
* \sa \ref api_trace */
-void rs_trace_stderr(rs_loglevel level, char const *msg);
+void rs_trace_stderr(rs_loglevel level, char const *msg);
/** Check whether the library was compiled with debugging trace.
*
* \returns True if the library contains trace code; otherwise false.
*
- * If this returns false, then trying to turn trace on will achieve
- * nothing.
+ * If this returns false, then trying to turn trace on will achieve nothing.
*
* \sa \ref api_trace */
-int rs_supports_trace(void);
+int rs_supports_trace(void);
-/** Convert \p from_len bytes at \p from_buf into a hex representation in
- * \p to_buf, which must be twice as long plus one byte for the null
- * terminator. */
-void rs_hexify(char *to_buf, void const *from_buf, int from_len);
+/** Convert \p from_len bytes at \p from_buf into a hex representation in \p
+ * to_buf, which must be twice as long plus one byte for the null terminator. */
+void rs_hexify(char *to_buf, void const *from_buf, int from_len);
/** Decode a base64 buffer in place.
*
@@ -163,99 +157,91 @@ void rs_base64(unsigned char const *buf, int n, char *out);
/** \enum rs_result Return codes from nonblocking rsync operations.
*
- * \sa rs_strerror()
- * \sa api_callbacks */
+ * \sa rs_strerror() \sa api_callbacks */
typedef enum rs_result {
- RS_DONE = 0, /**< Completed successfully. */
- RS_BLOCKED = 1, /**< Blocked waiting for more data. */
- RS_RUNNING = 2, /**< The job is still running, and not yet finished
- * or blocked. (This value should never be seen by
- * the application.) */
- RS_TEST_SKIPPED = 77, /**< Test neither passed or failed. */
- RS_IO_ERROR = 100, /**< Error in file or network IO. */
- RS_SYNTAX_ERROR = 101, /**< Command line syntax error. */
- RS_MEM_ERROR = 102, /**< Out of memory. */
- RS_INPUT_ENDED = 103, /**< Unexpected end of input file, perhaps due
- * to a truncated file or dropped network
- * connection. */
- RS_BAD_MAGIC = 104, /**< Bad magic number at start of
- stream. Probably not a librsync
- file, or possibly the wrong kind of
- file or from an incompatible
- library version. */
- RS_UNIMPLEMENTED = 105, /**< Author is lazy. */
- RS_CORRUPT = 106, /**< Unbelievable value in stream. */
+ RS_DONE = 0, /**< Completed successfully. */
+ RS_BLOCKED = 1, /**< Blocked waiting for more data. */
+ RS_RUNNING = 2, /**< The job is still running, and not yet
+ * finished or blocked. (This value should
+ * never be seen by the application.) */
+ RS_TEST_SKIPPED = 77, /**< Test neither passed or failed. */
+ RS_IO_ERROR = 100, /**< Error in file or network IO. */
+ RS_SYNTAX_ERROR = 101, /**< Command line syntax error. */
+ RS_MEM_ERROR = 102, /**< Out of memory. */
+ RS_INPUT_ENDED = 103, /**< Unexpected end of input file, perhaps due
+ * to a truncated file or dropped network
+ * connection. */
+ RS_BAD_MAGIC = 104, /**< Bad magic number at start of stream.
+ * Probably not a librsync file, or possibly
+ * the wrong kind of file or from an
+ * incompatible library version. */
+ RS_UNIMPLEMENTED = 105, /**< Author is lazy. */
+ RS_CORRUPT = 106, /**< Unbelievable value in stream. */
RS_INTERNAL_ERROR = 107, /**< Probably a library bug. */
- RS_PARAM_ERROR = 108 /**< Bad value passed in to library,
- * probably an application bug. */
+ RS_PARAM_ERROR = 108 /**< Bad value passed in to library, probably
+ * an application bug. */
} rs_result;
/** Return an English description of a ::rs_result value. */
char const *rs_strerror(rs_result r);
-/** Performance statistics from a librsync encoding or decoding
- * operation.
+/** Performance statistics from a librsync encoding or decoding operation.
*
- * \sa api_stats
- * \sa rs_format_stats()
- * \sa rs_log_stats() */
+ * \sa api_stats \sa rs_format_stats() \sa rs_log_stats() */
typedef struct rs_stats {
- char const *op; /**< Human-readable name of current
- * operation. For example, "delta". */
- int lit_cmds; /**< Number of literal commands. */
- rs_long_t lit_bytes; /**< Number of literal bytes. */
- rs_long_t lit_cmdbytes; /**< Number of bytes used in literal
- * command headers. */
+ char const *op; /**< Human-readable name of current operation.
+ * For example, "delta". */
+ int lit_cmds; /**< Number of literal commands. */
+ rs_long_t lit_bytes; /**< Number of literal bytes. */
+ rs_long_t lit_cmdbytes; /**< Number of bytes used in literal command
+ * headers. */
- rs_long_t copy_cmds, copy_bytes, copy_cmdbytes;
- rs_long_t sig_cmds, sig_bytes;
- int false_matches;
+ rs_long_t copy_cmds, copy_bytes, copy_cmdbytes;
+ rs_long_t sig_cmds, sig_bytes;
+ int false_matches;
- rs_long_t sig_blocks; /**< Number of blocks described by the
- signature. */
+ rs_long_t sig_blocks; /**< Number of blocks described by the
+ * signature. */
- size_t block_len;
+ size_t block_len;
- rs_long_t in_bytes; /**< Total bytes read from input. */
- rs_long_t out_bytes; /**< Total bytes written to output. */
+ rs_long_t in_bytes; /**< Total bytes read from input. */
+ rs_long_t out_bytes; /**< Total bytes written to output. */
- time_t start, end;
+ time_t start, end;
} rs_stats_t;
-
/** \typedef struct rs_mdfour rs_mdfour_t
*
* \brief MD4 message-digest accumulator.
*
- * \sa rs_mdfour(), rs_mdfour_begin(), rs_mdfour_update(),
- * rs_mdfour_result() */
+ * \sa rs_mdfour(), rs_mdfour_begin(), rs_mdfour_update(), rs_mdfour_result() */
typedef struct rs_mdfour rs_mdfour_t;
extern const int RS_MD4_SUM_LENGTH, RS_BLAKE2_SUM_LENGTH;
-#define RS_MAX_STRONG_SUM_LENGTH 32
+# define RS_MAX_STRONG_SUM_LENGTH 32
typedef uint32_t rs_weak_sum_t;
typedef unsigned char rs_strong_sum_t[RS_MAX_STRONG_SUM_LENGTH];
-void rs_mdfour(unsigned char *out, void const *in, size_t);
-void rs_mdfour_begin(/* @out@ */ rs_mdfour_t * md);
+void rs_mdfour(unsigned char *out, void const *in, size_t);
+void rs_mdfour_begin( /* @out@ */ rs_mdfour_t *md);
/** Feed some data into the MD4 accumulator.
*
- * \param md MD4 accumulator.
+ * \param md MD4 accumulator.
*
* \param in_void Data to add.
*
- * \param n Number of bytes fed in. */
-void rs_mdfour_update(rs_mdfour_t * md, void const *in_void,
- size_t n);
-void rs_mdfour_result(rs_mdfour_t * md, unsigned char *out);
+ * \param n Number of bytes fed in. */
+void rs_mdfour_update(rs_mdfour_t *md, void const *in_void, size_t n);
+void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out);
/** Return a human-readable representation of statistics.
*
- * The string is truncated if it does not fit. 100 characters should
- * be sufficient space.
+ * The string is truncated if it does not fit. 100 characters should be
+ * sufficient space.
*
* \param stats Statistics from an encoding or decoding operation.
*
@@ -265,125 +251,103 @@ void rs_mdfour_result(rs_mdfour_t * md, unsigned char *out);
*
* \return \p buf.
*
- * \sa \ref api_stats
- */
+ * \sa \ref api_stats */
char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size);
-/**
- * Write statistics into the current log as text.
+/** Write statistics into the current log as text.
*
- * \sa \ref api_stats
- * \sa \ref api_trace
- */
+ * \sa \ref api_stats \sa \ref api_trace */
int rs_log_stats(rs_stats_t const *stats);
-/**
- * \typedef rs_signature_t
- */
+/** \typedef rs_signature_t */
typedef struct rs_signature rs_signature_t;
-/**
- * Deep deallocation of checksums.
- */
+/** Deep deallocation of checksums. */
void rs_free_sumset(rs_signature_t *);
-/**
- * Dump signatures to the log.
- */
+/** Dump signatures to the log. */
void rs_sumset_dump(rs_signature_t const *);
-/**
- * Description of input and output buffers.
+/** Description of input and output buffers.
*
* On each call to ::rs_job_iter(), the caller can make available
*
- * - #avail_in bytes of input data at #next_in
+ * - #avail_in bytes of input data at #next_in
*
- * - #avail_out bytes of output space at #next_out
+ * - #avail_out bytes of output space at #next_out
*
- * - or some of both
+ * - or some of both
*
* Buffers must be allocated and passed in by the caller.
*
- * On input, the buffers structure must contain the address and length of
- * the input and output buffers. The library updates these values to
- * indicate the amount of \b remaining buffer. So, on return,
- * #avail_out is not the amount of output data produced, but rather the
- * amount of output buffer space still available.
- *
- * This means that the values on
- * return are consistent with the values on entry, and suitable to be passed
- * in on a second call, but they don't directly tell you how much output
- * data was produced.
- *
- * Note also that if *#avail_in is nonzero on return, then not all of
- * the input data has been consumed. The caller should either provide
- * more output buffer space and call ::rs_job_iter() again passing the same
- * #next_in and #avail_in, or put the remaining input data into some
- * persistent buffer and call rs_job_iter() with it again when there is
- * more output space.
- *
- * \sa rs_job_iter()
- */
+ * On input, the buffers structure must contain the address and length of the
+ * input and output buffers. The library updates these values to indicate the
+ * amount of \b remaining buffer. So, on return, #avail_out is not the amount
+ * of output data produced, but rather the amount of output buffer space still
+ * available.
+ *
+ * This means that the values on return are consistent with the values on
+ * entry, and suitable to be passed in on a second call, but they don't
+ * directly tell you how much output data was produced.
+ *
+ * Note also that if *#avail_in is nonzero on return, then not all of the input
+ * data has been consumed. The caller should either provide more output buffer
+ * space and call ::rs_job_iter() again passing the same #next_in and
+ * #avail_in, or put the remaining input data into some persistent buffer and
+ * call rs_job_iter() with it again when there is more output space.
+ *
+ * \sa rs_job_iter() */
struct rs_buffers_s {
/** Next input byte.
*
- * References a pointer which on entry should point to
- * the start of the data to be encoded. Updated to point to the byte
- * after the last one consumed.
- **/
+ * References a pointer which on entry should point to the start of the
+ * data to be encoded. Updated to point to the byte after the last one
+ * consumed. */
char *next_in;
/** Number of bytes available at next_in.
*
- * References the length of available input. Updated to
- * be the number of unused data bytes, which will be zero if all the
- * input was consumed. May be zero if there is no new input, but the
- * caller just wants to drain output.
- */
+ * References the length of available input. Updated to be the number of
+ * unused data bytes, which will be zero if all the input was consumed.
+ * May be zero if there is no new input, but the caller just wants to drain
+ * output. */
size_t avail_in;
- /** True if there is no more data after this. */
+ /** True if there is no more data after this. */
int eof_in;
/** Next output byte should be put there.
*
- * References a pointer which on entry points to the
- * start of the output buffer. Updated to point to the byte after the
- * last one filled.
- */
+ * References a pointer which on entry points to the start of the output
+ * buffer. Updated to point to the byte after the last one filled. */
char *next_out;
/** Remaining free space at next_out.
*
- * References the size of available output buffer.
- * Updated to the size of unused output buffer.
- */
+ * References the size of available output buffer. Updated to the size of
+ * unused output buffer. */
size_t avail_out;
};
-/**
- * \sa ::rs_buffers_s
- */
+/** \sa ::rs_buffers_s */
typedef struct rs_buffers_s rs_buffers_t;
/** Default block length, if not determined by any other factors. */
-#define RS_DEFAULT_BLOCK_LEN 2048
+# define RS_DEFAULT_BLOCK_LEN 2048
/** Job of work to be done.
*
- * Created by functions such as rs_sig_begin(), and then iterated
- * over by rs_job_iter().
+ * Created by functions such as rs_sig_begin(), and then iterated over by
+ * rs_job_iter().
*
* The contents are opaque to the application, and instances are always
* allocated by the library.
*
- * \sa \ref api_streaming
- * \sa rs_job */
+ * \sa \ref api_streaming \sa rs_job */
typedef struct rs_job rs_job_t;
-/** Run a ::rs_job state machine until it blocks
- * (::RS_BLOCKED), returns an error, or completes (::RS_DONE).
+/** Run a ::rs_job state machine until it blocks (::RS_BLOCKED), returns an
+ * error, or completes (::RS_DONE).
*
* \param job Description of job state.
*
@@ -391,13 +355,12 @@ typedef struct rs_job rs_job_t;
*
* \return The ::rs_result that caused iteration to stop.
*
- * \c buffers->eof_in should be true if there is no more data after what's
- * in the
- * input buffer. The final block checksum will run across whatever's
- * in there, without trying to accumulate anything else.
+ * \c buffers->eof_in should be true if there is no more data after what's in
+ * the input buffer. The final block checksum will run across whatever's in
+ * there, without trying to accumulate anything else.
*
* \sa \ref api_streaming */
-rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);
+rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);
/** Type of application-supplied function for rs_job_drive().
*
@@ -405,17 +368,16 @@ rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);
typedef rs_result rs_driven_cb(rs_job_t *job, rs_buffers_t *buf,
void *opaque);
-/** Actively process a job, by making callbacks to fill and empty the
- * buffers until the job is done. */
-rs_result rs_job_drive(rs_job_t *job, rs_buffers_t *buf,
- rs_driven_cb in_cb, void *in_opaque,
- rs_driven_cb out_cb, void *out_opaque);
+/** Actively process a job, by making callbacks to fill and empty the buffers
+ * until the job is done. */
+rs_result rs_job_drive(rs_job_t *job, rs_buffers_t *buf, rs_driven_cb in_cb,
+ void *in_opaque, rs_driven_cb out_cb, void *out_opaque);
/** Return a pointer to the statistics in a job. */
-const rs_stats_t * rs_job_statistics(rs_job_t *job);
+const rs_stats_t *rs_job_statistics(rs_job_t *job);
/** Deallocate job state. */
-rs_result rs_job_free(rs_job_t *);
+rs_result rs_job_free(rs_job_t *);
/** Start generating a signature.
*
@@ -432,8 +394,7 @@ rs_result rs_job_free(rs_job_t *);
* at zero to get the full strength.
*
* \sa rs_sig_file() */
-rs_job_t *rs_sig_begin(size_t new_block_len,
- size_t strong_sum_len,
+rs_job_t *rs_sig_begin(size_t new_block_len, size_t strong_sum_len,
rs_magic_number sig_magic);
/** Prepare to compute a streaming delta.
@@ -442,71 +403,63 @@ rs_job_t *rs_sig_begin(size_t new_block_len,
* delta format. */
rs_job_t *rs_delta_begin(rs_signature_t *);
-/** Read a signature from a file into an ::rs_signature structure
- * in memory.
+/** Read a signature from a file into an ::rs_signature structure in memory.
*
- * Once there, it can be used to generate a delta to a newer version of
- * the file.
+ * Once there, it can be used to generate a delta to a newer version of the
+ * file.
*
- * \note After loading the signatures, you must call
- * \ref rs_build_hash_table() before you can use them. */
+ * \note After loading the signatures, you must call \ref rs_build_hash_table()
+ * before you can use them. */
rs_job_t *rs_loadsig_begin(rs_signature_t **);
/** Call this after loading a signature to index it.
*
* Use rs_free_sumset() to release it after use. */
-rs_result rs_build_hash_table(rs_signature_t* sums);
+rs_result rs_build_hash_table(rs_signature_t *sums);
/** Callback used to retrieve parts of the basis file.
*
* \param pos Position where copying should begin.
*
- * \param len On input, the amount of data that should be retrieved.
- * Updated to show how much is actually available, but should not be greater
- * than the input value.
+ * \param len On input, the amount of data that should be retrieved. Updated to
+ * show how much is actually available, but should not be greater than the
+ * input value.
*
- * \param buf On input, a buffer of at least \p *len bytes. May be
- * updated to point to a buffer allocated by the callback if it
- * prefers. */
-typedef rs_result rs_copy_cb(void *opaque, rs_long_t pos,
- size_t *len, void **buf);
+ * \param buf On input, a buffer of at least \p *len bytes. May be updated to
+ * point to a buffer allocated by the callback if it prefers. */
+typedef rs_result rs_copy_cb(void *opaque, rs_long_t pos, size_t *len,
+ void **buf);
-/** Apply a \a delta to a \a basis file to recreate
- * the \a new file.
+/** Apply a \a delta to a \a basis file to recreate the \a new file.
*
- * This gives you back a ::rs_job_t object, which can be cranked by
- * calling rs_job_iter() and updating the stream pointers. When
- * finished, call rs_job_free() to dispose of it.
+ * This gives you back a ::rs_job_t object, which can be cranked by calling
+ * rs_job_iter() and updating the stream pointers. When finished, call
+ * rs_job_free() to dispose of it.
*
- * \param copy_cb Callback used to retrieve content from the basis
- * file.
+ * \param copy_cb Callback used to retrieve content from the basis file.
*
- * \param copy_arg Opaque environment pointer passed through to the
- * callback.
+ * \param copy_arg Opaque environment pointer passed through to the callback.
*
- * \todo As output is produced, accumulate the MD4 checksum of the
- * output. Then if we find a CHECKSUM command we can check it's
- * contents against the output.
+ * \todo As output is produced, accumulate the MD4 checksum of the output.
+ * Then if we find a CHECKSUM command we can check it's contents against the
+ * output.
*
* \todo Implement COPY commands.
*
- * \sa rs_patch_file()
- * \sa \ref api_streaming */
-rs_job_t *rs_patch_begin(rs_copy_cb *copy_cb, void *copy_arg);
+ * \sa rs_patch_file() \sa \ref api_streaming */
+rs_job_t *rs_patch_begin(rs_copy_cb * copy_cb, void *copy_arg);
-#ifndef RSYNC_NO_STDIO_INTERFACE
-#include <stdio.h>
+# ifndef RSYNC_NO_STDIO_INTERFACE
+# include <stdio.h>
/** Buffer sizes for file IO.
*
- * The default 0 means use the recommended buffer size for the
- * operation being performed, any other value will override the
- * recommended sizes. You probably only need to change these in
- * testing. */
+ * The default 0 means use the recommended buffer size for the operation being
+ * performed, any other value will override the recommended sizes. You probably
+ * only need to change these in testing. */
extern int rs_inbuflen, rs_outbuflen;
-/** Generate the signature of a basis file, and write it out to
- * another.
+/** Generate the signature of a basis file, and write it out to another.
*
* \param old_file Stdio readable file whose signature will be generated.
*
@@ -516,16 +469,14 @@ extern int rs_inbuflen, rs_outbuflen;
*
* \param strong_len truncated length of strong checksums, in bytes
*
- * \param sig_magic A signature magic number indicating
- * what format to use.
+ * \param sig_magic A signature magic number indicating what format to use.
*
* \param stats Optional pointer to receive statistics.
*
* \sa \ref api_whole */
-rs_result rs_sig_file(FILE *old_file, FILE *sig_file,
- size_t block_len, size_t strong_len,
- rs_magic_number sig_magic,
- rs_stats_t *stats);
+rs_result rs_sig_file(FILE *old_file, FILE *sig_file, size_t block_len,
+ size_t strong_len, rs_magic_number sig_magic,
+ rs_stats_t *stats);
/** Load signatures from a signature file into memory.
*
@@ -537,7 +488,7 @@ rs_result rs_sig_file(FILE *old_file, FILE *sig_file,
*
* \sa \ref api_whole */
rs_result rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset,
- rs_stats_t *stats);
+ rs_stats_t *stats);
/** ::rs_copy_cb that reads from a stdio file. */
rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf);
@@ -545,16 +496,18 @@ rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf);
/** Generate a delta between a signature and a new file into a delta file.
*
* \sa \ref api_whole */
-rs_result rs_delta_file(rs_signature_t *, FILE *new_file, FILE *delta_file, rs_stats_t *);
+rs_result rs_delta_file(rs_signature_t *, FILE *new_file, FILE *delta_file,
+ rs_stats_t *);
/** Apply a patch, relative to a basis, into a new file.
*
* \sa \ref api_whole */
-rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file, rs_stats_t *);
-#endif /* !RSYNC_NO_STDIO_INTERFACE */
+rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file,
+ rs_stats_t *);
+# endif /* !RSYNC_NO_STDIO_INTERFACE */
-#ifdef __cplusplus
+# ifdef __cplusplus
} /* extern "C" */
-#endif
+# endif
-#endif /* !_RSYNC_H */
+#endif /* !_RSYNC_H */
diff --git a/src/mdfour.c b/src/mdfour.c
index 986bbc0..458d053 100644
--- a/src/mdfour.c
+++ b/src/mdfour.c
@@ -23,22 +23,20 @@
/** \file mdfour.c MD4 message digest algorithm.
*
- * \todo Perhaps use the MD4 routine from OpenSSL if it's installed.
- * It's probably not worth the trouble.
+ * \todo Perhaps use the MD4 routine from OpenSSL if it's installed. It's
+ * probably not worth the trouble.
*
- * This was originally written by Andrew Tridgell for use in Samba.
- * It was then modified by;
+ * This was originally written by Andrew Tridgell for use in Samba. It was then
+ * modified by;
*
- * 2002-06-xx: Robert Weber <robert.weber@Colorado.edu>
- * optimisations and fixed >512M support.
+ * 2002-06-xx: Robert Weber <robert.weber@Colorado.edu> optimisations and fixed
+ * >512M support.
*
- * 2002-06-27: Donovan Baarda <abo@minkirri.apana.org.au>
- * further optimisations and cleanups.
+ * 2002-06-27: Donovan Baarda <abo@minkirri.apana.org.au> further optimisations
+ * and cleanups.
*
- * 2004-09-09: Simon Law <sfllaw@debian.org>
- * handle little-endian machines that can't do unaligned access
- * (e.g. ia64, pa-risc).
- */
+ * 2004-09-09: Simon Law <sfllaw@debian.org> handle little-endian machines that
+ * can't do unaligned access (e.g. ia64, pa-risc). */
#include "config.h"
@@ -50,7 +48,6 @@
#include "trace.h"
#include "mdfour.h"
-
#define F(X,Y,Z) (((X)&(Y)) | ((~(X))&(Z)))
#define G(X,Y,Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))
#define H(X,Y,Z) ((X)^(Y)^(Z))
@@ -67,31 +64,23 @@ static unsigned char PADDING[64] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
+static void rs_mdfour_block(rs_mdfour_t *md, void const *p);
-static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p);
-
-
-
-/**
- * Update an MD4 accumulator from a 64-byte chunk.
+/** Update an MD4 accumulator from a 64-byte chunk.
*
- * This cannot be used for the last chunk of the file, which must be
- * padded and contain the file length. rs_mdfour_tail() is used for
- * that.
+ * This cannot be used for the last chunk of the file, which must be padded and
+ * contain the file length. rs_mdfour_tail() is used for that.
*
- * \todo Recode to be fast, and to use system integer types. Perhaps
- * if we can find an mdfour implementation already on the system
- * (e.g. in OpenSSL) then we should use it instead of our own?
+ * \todo Recode to be fast, and to use system integer types. Perhaps if we can
+ * find an mdfour implementation already on the system (e.g. in OpenSSL) then
+ * we should use it instead of our own?
*
- * \param X A series of integer, read little-endian from the file.
- */
-static void
-rs_mdfour64(rs_mdfour_t * m, const void *p)
+ * \param X A series of integer, read little-endian from the file. */
+static void rs_mdfour64(rs_mdfour_t *m, const void *p)
{
- uint32_t AA, BB, CC, DD;
- uint32_t A, B, C, D;
- const uint32_t *X = (const uint32_t *) p;
+ uint32_t AA, BB, CC, DD;
+ uint32_t A, B, C, D;
+ const uint32_t *X = (const uint32_t *)p;
A = m->A;
B = m->B;
@@ -164,17 +153,14 @@ rs_mdfour64(rs_mdfour_t * m, const void *p)
m->D = D;
}
-
-/**
- * These next routines are necessary because MD4 is specified in terms of
+/** These next routines are necessary because MD4 is specified in terms of
* little-endian int32s, but we have a byte buffer. On little-endian
* platforms, I think we can just use the buffer pointer directly.
*
* There are some nice endianness routines in glib, including assembler
* variants. If we ever depended on glib, then it could be good to use them
* instead. */
-inline static void
-copy4( /* @out@ */ unsigned char *out, uint32_t const x)
+inline static void copy4( /* @out@ */ unsigned char *out, uint32_t const x)
{
out[0] = x;
out[1] = x >> 8;
@@ -182,12 +168,10 @@ copy4( /* @out@ */ unsigned char *out, uint32_t const x)
out[3] = x >> 24;
}
-
/* We need this if there is a uint64 */
-/* --robert.weber@Colorado.edu */
+/* --robert.weber@Colorado.edu */
#ifdef HAVE_UINT64
-inline static void
-copy8( /* @out@ */ unsigned char *out, uint64_t const x)
+inline static void copy8( /* @out@ */ unsigned char *out, uint64_t const x)
{
out[0] = x;
out[1] = x >> 8;
@@ -198,15 +182,13 @@ copy8( /* @out@ */ unsigned char *out, uint64_t const x)
out[6] = x >> 48;
out[7] = x >> 56;
}
-#endif /* HAVE_UINT64 */
-
+#endif /* HAVE_UINT64 */
/* We only need this if we are big-endian */
#ifdef WORDS_BIGENDIAN
-inline static void
-copy64( /* @out@ */ uint32_t * M, unsigned char const *in)
+inline static void copy64( /* @out@ */ uint32_t *M, unsigned char const *in)
{
- int i=16;
+ int i = 16;
while (i--) {
*M++ = (in[3] << 24) | (in[2] << 16) | (in[1] << 8) | in[0];
@@ -214,60 +196,51 @@ copy64( /* @out@ */ uint32_t * M, unsigned char const *in)
}
}
-
-/**
- * Accumulate a block, making appropriate conversions for bigendian
- * machines.
+/** Accumulate a block, making appropriate conversions for bigendian machines.
*/
-inline static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p)
+inline static void rs_mdfour_block(rs_mdfour_t *md, void const *p)
{
- uint32_t M[16];
+ uint32_t M[16];
copy64(M, p);
rs_mdfour64(md, M);
}
-
-#else /* WORDS_BIGENDIAN */
+#else /* WORDS_BIGENDIAN */
# ifdef __i386__
/* If we are on an IA-32 machine, we can process directly. */
-inline static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p)
+inline static void rs_mdfour_block(rs_mdfour_t *md, void const *p)
{
- rs_mdfour64(md,p);
+ rs_mdfour64(md, p);
}
-# else /* !WORDS_BIGENDIAN && !__i386__ */
+# else /* !WORDS_BIGENDIAN && !__i386__ */
-/* We are little-endian, but not on i386 and therefore may not be able
- * to do unaligned access safely/quickly.
- *
- * So if the input is not already aligned correctly, copy it to an
- * aligned buffer first. */
-inline static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p)
+/* We are little-endian, but not on i386 and therefore may not be able to do
+ unaligned access safely/quickly.
+
+ So if the input is not already aligned correctly, copy it to an aligned
+ buffer first. */
+inline static void rs_mdfour_block(rs_mdfour_t *md, void const *p)
{
- unsigned long ptrval = (unsigned long) p;
+ unsigned long ptrval = (unsigned long)p;
if (ptrval & 3) {
- uint32_t M[16];
+ uint32_t M[16];
memcpy(M, p, 16 * sizeof(uint32_t));
rs_mdfour64(md, M);
} else {
- rs_mdfour64(md, (const uint32_t *) p);
+ rs_mdfour64(md, (const uint32_t *)p);
}
}
-# endif /* !__i386__ */
-#endif /* WORDS_BIGENDIAN */
+# endif /* !__i386__ */
+#endif /* WORDS_BIGENDIAN */
-
-void
-rs_mdfour_begin(rs_mdfour_t * md)
+void rs_mdfour_begin(rs_mdfour_t *md)
{
memset(md, 0, sizeof(*md));
md->A = 0x67452301;
@@ -281,64 +254,57 @@ rs_mdfour_begin(rs_mdfour_t * md)
#endif
}
-
-/**
- * Handle special behaviour for processing the last block of a file
- * when calculating its MD4 checksum.
+/** Handle special behaviour for processing the last block of a file when
+ * calculating its MD4 checksum.
*
* This must be called exactly once per file.
*
- * Modified by Robert Weber to use uint64 in order that we can sum files
- * > 2^29 = 512 MB.
- * --Robert.Weber@colorado.edu
- */
-static void
-rs_mdfour_tail(rs_mdfour_t * m)
+ * Modified by Robert Weber to use uint64 in order that we can sum files > 2^29
+ * = 512 MB. --Robert.Weber@colorado.edu */
+static void rs_mdfour_tail(rs_mdfour_t *m)
{
#ifdef HAVE_UINT64
- uint64_t b;
-#else /* HAVE_UINT64 */
- uint32_t b[2];
-#endif /* HAVE_UINT64 */
- unsigned char buf[8];
- size_t pad_len;
+ uint64_t b;
+#else /* HAVE_UINT64 */
+ uint32_t b[2];
+#endif /* HAVE_UINT64 */
+ unsigned char buf[8];
+ size_t pad_len;
/* convert the totalN byte count into a bit count buffer */
#ifdef HAVE_UINT64
b = m->totalN << 3;
copy8(buf, b);
-#else /* HAVE_UINT64 */
+#else /* HAVE_UINT64 */
b[0] = m->totalN_lo << 3;
b[1] = ((m->totalN_hi << 3) | (m->totalN_lo >> 29));
copy4(buf, b[0]);
copy4(buf + 4, b[1]);
-#endif /* HAVE_UINT64 */
+#endif /* HAVE_UINT64 */
/* calculate length and process the padding data */
- pad_len=(m->tail_len <56) ? (56 - m->tail_len) : (120 - m->tail_len);
- rs_mdfour_update(m,PADDING,pad_len);
+ pad_len = (m->tail_len < 56) ? (56 - m->tail_len) : (120 - m->tail_len);
+ rs_mdfour_update(m, PADDING, pad_len);
/* process the bit count */
- rs_mdfour_update(m,buf,8);
+ rs_mdfour_update(m, buf, 8);
}
-
-void
-rs_mdfour_update(rs_mdfour_t * md, void const *in_void, size_t n)
+void rs_mdfour_update(rs_mdfour_t *md, void const *in_void, size_t n)
{
- unsigned char const *in = (unsigned char const *) in_void;
+ unsigned char const *in = (unsigned char const *)in_void;
/* increment totalN */
#ifdef HAVE_UINT64
- md->totalN+=n;
-#else /* HAVE_UINT64 */
+ md->totalN += n;
+#else /* HAVE_UINT64 */
if ((md->totalN_lo += n) < n)
- md->totalN_hi++;
-#endif /* HAVE_UINT64 */
+ md->totalN_hi++;
+#endif /* HAVE_UINT64 */
- /* If there's any leftover data in the tail buffer, then first we have
- * to make it up to a whole block to process it. */
+ /* If there's any leftover data in the tail buffer, then first we have to
+ make it up to a whole block to process it. */
if (md->tail_len) {
- size_t tail_gap = 64 - md->tail_len;
+ size_t tail_gap = 64 - md->tail_len;
if (tail_gap <= n) {
memcpy(&md->tail[md->tail_len], in, tail_gap);
rs_mdfour_block(md, md->tail);
@@ -353,16 +319,14 @@ rs_mdfour_update(rs_mdfour_t * md, void const *in_void, size_t n)
in += 64;
n -= 64;
}
- /* Put remaining bytes onto tail*/
+ /* Put remaining bytes onto tail */
if (n) {
memcpy(&md->tail[md->tail_len], in, n);
md->tail_len += n;
}
}
-
-void
-rs_mdfour_result(rs_mdfour_t * md, unsigned char *out)
+void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out)
{
rs_mdfour_tail(md);
@@ -372,11 +336,9 @@ rs_mdfour_result(rs_mdfour_t * md, unsigned char *out)
copy4(out + 12, md->D);
}
-
-void
-rs_mdfour(unsigned char *out, void const *in, size_t n)
+void rs_mdfour(unsigned char *out, void const *in, size_t n)
{
- rs_mdfour_t md;
+ rs_mdfour_t md;
rs_mdfour_begin(&md);
rs_mdfour_update(&md, in, n);
diff --git a/src/mdfour.h b/src/mdfour.h
index e72643e..0871eff 100644
--- a/src/mdfour.h
+++ b/src/mdfour.h
@@ -20,16 +20,14 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/** \private
- * Internal state while computing an MD4 hash.
- */
+/** \private Internal state while computing an MD4 hash. */
struct rs_mdfour {
- unsigned int A, B, C, D;
+ unsigned int A, B, C, D;
#if HAVE_UINT64
- uint64_t totalN;
+ uint64_t totalN;
#else
- uint32_t totalN_hi, totalN_lo;
+ uint32_t totalN_hi, totalN_lo;
#endif
- int tail_len;
- unsigned char tail[64];
+ int tail_len;
+ unsigned char tail[64];
};
diff --git a/src/mksum.c b/src/mksum.c
index c95e44e..8e9d56a 100644
--- a/src/mksum.c
+++ b/src/mksum.c
@@ -20,19 +20,15 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-/**
- * \file mksum.c Generate file signatures.
+/** \file mksum.c Generate file signatures.
*
- * Generating checksums is pretty easy, since we can always just
- * process whatever data is available. When a whole block has
- * arrived, or we've reached the end of the file, we write the
- * checksum out.
+ * Generating checksums is pretty easy, since we can always just process
+ * whatever data is available. When a whole block has arrived, or we've
+ * reached the end of the file, we write the checksum out.
*
- * \todo Perhaps force blocks to be a multiple of 64 bytes, so that we
- * can be sure checksum generation will be more efficient. I guess it
- * will be OK at the moment, though, because tails are only used if
- * necessary. */
+ * \todo Perhaps force blocks to be a multiple of 64 bytes, so that we can be
+ * sure checksum generation will be more efficient. I guess it will be OK at
+ * the moment, though, because tails are only used if necessary. */
#include "config.h"
@@ -48,24 +44,19 @@
#include "netint.h"
#include "trace.h"
-
/* Possible state functions for signature generation. */
static rs_result rs_sig_s_header(rs_job_t *);
static rs_result rs_sig_s_generate(rs_job_t *);
-
-
-/**
- * State of trying to send the signature header.
- * \private
- */
+/** State of trying to send the signature header. \private */
static rs_result rs_sig_s_header(rs_job_t *job)
{
rs_signature_t *sig = job->signature;
rs_result result;
- if ((result = rs_signature_init(sig, job->sig_magic, job->sig_block_len,
- job->sig_strong_len, 0)) != RS_DONE)
+ if ((result =
+ rs_signature_init(sig, job->sig_magic, job->sig_block_len,
+ job->sig_strong_len, 0)) != RS_DONE)
return result;
rs_squirt_n4(job, sig->magic);
rs_squirt_n4(job, sig->block_len);
@@ -78,43 +69,34 @@ static rs_result rs_sig_s_header(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Generate the checksums for a block and write it out. Called when
- * we already know we have enough data in memory at \p block.
- * \private
- */
-static rs_result
-rs_sig_do_block(rs_job_t *job, const void *block, size_t len)
+/** Generate the checksums for a block and write it out. Called when we
+ * already know we have enough data in memory at \p block. \private */
+static rs_result rs_sig_do_block(rs_job_t *job, const void *block, size_t len)
{
- rs_signature_t *sig = job->signature;
- rs_weak_sum_t weak_sum;
- rs_strong_sum_t strong_sum;
+ rs_signature_t *sig = job->signature;
+ rs_weak_sum_t weak_sum;
+ rs_strong_sum_t strong_sum;
weak_sum = rs_calc_weak_sum(block, len);
rs_signature_calc_strong_sum(sig, block, len, &strong_sum);
rs_squirt_n4(job, weak_sum);
rs_tube_write(job, strong_sum, sig->strong_sum_len);
if (rs_trace_enabled()) {
- char strong_sum_hex[RS_MAX_STRONG_SUM_LENGTH * 2 + 1];
+ char strong_sum_hex[RS_MAX_STRONG_SUM_LENGTH * 2 + 1];
rs_hexify(strong_sum_hex, strong_sum, sig->strong_sum_len);
- rs_trace("sent block: weak="FMT_WEAKSUM", strong=%s", weak_sum, strong_sum_hex);
+ rs_trace("sent block: weak=" FMT_WEAKSUM ", strong=%s", weak_sum,
+ strong_sum_hex);
}
job->stats.sig_blocks++;
return RS_RUNNING;
}
-
-/**
- * State of reading a block and trying to generate its sum.
- * \private
- */
-static rs_result
-rs_sig_s_generate(rs_job_t *job)
+/** State of reading a block and trying to generate its sum. \private */
+static rs_result rs_sig_s_generate(rs_job_t *job)
{
- rs_result result;
- size_t len;
- void *block;
+ rs_result result;
+ size_t len;
+ void *block;
/* must get a whole block, otherwise try again */
len = job->signature->block_len;
@@ -128,13 +110,12 @@ rs_sig_s_generate(rs_job_t *job)
rs_trace("generate stopped: %s", rs_strerror(result));
return result;
}
- rs_trace("got "FMT_SIZE" byte block", len);
+ rs_trace("got " FMT_SIZE " byte block", len);
return rs_sig_do_block(job, block, len);
}
-
-rs_job_t * rs_sig_begin(size_t new_block_len, size_t strong_sum_len,
- rs_magic_number sig_magic)
+rs_job_t *rs_sig_begin(size_t new_block_len, size_t strong_sum_len,
+ rs_magic_number sig_magic)
{
rs_job_t *job;
diff --git a/src/msg.c b/src/msg.c
index c2f6b65..e75134d 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -35,10 +35,9 @@
/** \file msg.c error messages for re_result values.
*
- * \todo (Suggestion by tridge) Add a function which outputs a
- * complete text description of a job, including only the fields
- * relevant to the current encoding function.
- */
+ * \todo (Suggestion by tridge) Add a function which outputs a complete text
+ * description of a job, including only the fields relevant to the current
+ * encoding function. */
#include "config.h"
diff --git a/src/netint.c b/src/netint.c
index 04a9d0b..20a22c4 100644
--- a/src/netint.c
+++ b/src/netint.c
@@ -29,19 +29,18 @@
/** \file netint.c Network-byte-order output to the tube.
*
- * All the `suck' routines return a result code. The most common
- * values are RS_DONE if they have enough data, or RS_BLOCKED if there
- * is not enough input to proceed.
+ * All the `suck' routines return a result code. The most common values are
+ * RS_DONE if they have enough data, or RS_BLOCKED if there is not enough input
+ * to proceed.
*
- * All the netint operations are done in a fairly simpleminded way,
- * since we don't want to rely on stdint types that may not be
- * available on some platforms.
+ * All the netint operations are done in a fairly simpleminded way, since we
+ * don't want to rely on stdint types that may not be available on some
+ * platforms.
*
- * \todo If we don't have <stdint.h> (or perhaps even if we do),
- * determine endianness and integer size by hand and use that to do
- * our own conversion routines. We possibly need this anyhow to do
- * 64-bit integers, since there seems to be no ntohs() analog.
- */
+ * \todo If we don't have <stdint.h> (or perhaps even if we do), determine
+ * endianness and integer size by hand and use that to do our own conversion
+ * routines. We possibly need this anyhow to do 64-bit integers, since there
+ * seems to be no ntohs() analog. */
#include "config.h"
@@ -60,41 +59,32 @@
#define RS_MAX_INT_BYTES 8
-
-/**
- * \brief Write a single byte to a stream output.
- */
-rs_result
-rs_squirt_byte(rs_job_t *job, unsigned char d)
+/** Write a single byte to a stream output. */
+rs_result rs_squirt_byte(rs_job_t *job, unsigned char d)
{
rs_tube_write(job, &d, 1);
return RS_DONE;
}
-
-/**
- * \brief Write a variable-length integer to a stream.
+/** Write a variable-length integer to a stream.
*
* \param job Job of data.
*
* \param d Datum to write out.
*
- * \param len Length of integer, in bytes.
- */
-rs_result
-rs_squirt_netint(rs_job_t *job, rs_long_t d, int len)
+ * \param len Length of integer, in bytes. */
+rs_result rs_squirt_netint(rs_job_t *job, rs_long_t d, int len)
{
- unsigned char buf[RS_MAX_INT_BYTES];
- int i;
+ unsigned char buf[RS_MAX_INT_BYTES];
+ int i;
if (len <= 0 || len > RS_MAX_INT_BYTES) {
rs_error("Illegal integer length %d", len);
return RS_INTERNAL_ERROR;
}
- /* Fill the output buffer with a bigendian representation of the
- * number. */
- for (i = len-1; i >=0; i--) {
+ /* Fill the output buffer with a bigendian representation of the number. */
+ for (i = len - 1; i >= 0; i--) {
buf[i] = d; /* truncated */
d >>= 8;
}
@@ -104,66 +94,55 @@ rs_squirt_netint(rs_job_t *job, rs_long_t d, int len)
return RS_DONE;
}
-
-
-rs_result
-rs_squirt_n4(rs_job_t *job, int val)
+rs_result rs_squirt_n4(rs_job_t *job, int val)
{
return rs_squirt_netint(job, val, 4);
}
-
-
-rs_result
-rs_suck_netint(rs_job_t *job, rs_long_t *v, int len)
+rs_result rs_suck_netint(rs_job_t *job, rs_long_t *v, int len)
{
- unsigned char *buf;
- int i;
- rs_result result;
+ unsigned char *buf;
+ int i;
+ rs_result result;
if (len <= 0 || len > RS_MAX_INT_BYTES) {
rs_error("Illegal integer length %d", len);
return RS_INTERNAL_ERROR;
}
- if ((result = rs_scoop_read(job, len, (void **) &buf)) != RS_DONE)
+ if ((result = rs_scoop_read(job, len, (void **)&buf)) != RS_DONE)
return result;
*v = 0;
for (i = 0; i < len; i++) {
- *v = *v<<8 | buf[i];
+ *v = *v << 8 | buf[i];
}
return RS_DONE;
}
-
-rs_result
-rs_suck_byte(rs_job_t *job, unsigned char *v)
+rs_result rs_suck_byte(rs_job_t *job, unsigned char *v)
{
void *inb;
rs_result result;
if ((result = rs_scoop_read(job, 1, &inb)) == RS_DONE)
- *v = *((unsigned char *) inb);
+ *v = *((unsigned char *)inb);
return result;
}
-
-rs_result
-rs_suck_n4(rs_job_t *job, int *v)
+rs_result rs_suck_n4(rs_job_t *job, int *v)
{
- rs_result result;
- rs_long_t d;
+ rs_result result;
+ rs_long_t d;
result = rs_suck_netint(job, &d, 4);
*v = d;
return result;
}
-
int rs_int_len(rs_long_t val)
{
if (!(val & ~(rs_long_t)0xff))
@@ -175,7 +154,7 @@ int rs_int_len(rs_long_t val)
else if (!(val & ~(rs_long_t)0xffffffffffffffff))
return 8;
else {
- rs_fatal("can't encode integer "FMT_LONG" yet", val);
+ rs_fatal("can't encode integer " FMT_LONG " yet", val);
return -1;
}
}
diff --git a/src/netint.h b/src/netint.h
index e75d268..4f7607a 100644
--- a/src/netint.h
+++ b/src/netint.h
@@ -1,20 +1,20 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
* Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/patch.c b/src/patch.c
index 2daef7e..1537795 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -19,7 +19,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
/*=
| This is Tranquility Base.
*/
@@ -41,8 +40,6 @@
#include "stream.h"
#include "job.h"
-
-
static rs_result rs_patch_s_cmdbyte(rs_job_t *);
static rs_result rs_patch_s_params(rs_job_t *);
static rs_result rs_patch_s_run(rs_job_t *);
@@ -50,12 +47,8 @@ static rs_result rs_patch_s_literal(rs_job_t *);
static rs_result rs_patch_s_copy(rs_job_t *);
static rs_result rs_patch_s_copying(rs_job_t *);
-
-/**
- * State of trying to read the first byte of a command. Once we've
- * taken that in, we can know how much data to read to get the
- * arguments.
- */
+/** State of trying to read the first byte of a command. Once we've taken
+ * that in, we can know how much data to read to get the arguments. */
static rs_result rs_patch_s_cmdbyte(rs_job_t *job)
{
rs_result result;
@@ -65,7 +58,8 @@ static rs_result rs_patch_s_cmdbyte(rs_job_t *job)
job->cmd = &rs_prototab[job->op];
- rs_trace("got command %#04x (%s), len_1="FMT_SIZE"", job->op, rs_op_kind_name(job->cmd->kind), job->cmd->len_1);
+ rs_trace("got command %#04x (%s), len_1=" FMT_SIZE "", job->op,
+ rs_op_kind_name(job->cmd->kind), job->cmd->len_1);
if (job->cmd->len_1)
job->statefn = rs_patch_s_params;
@@ -77,11 +71,8 @@ static rs_result rs_patch_s_cmdbyte(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Called after reading a command byte to pull in its parameters and
- * then setup to execute the command.
- */
+/** Called after reading a command byte to pull in its parameters and then
+ * setup to execute the command. */
static rs_result rs_patch_s_params(rs_job_t *job)
{
rs_result result;
@@ -109,11 +100,7 @@ static rs_result rs_patch_s_params(rs_job_t *job)
return RS_RUNNING;
}
-
-
-/**
- * Called when we've read in the whole command and we need to execute it.
- */
+/** Called when we've read in the whole command and we need to execute it. */
static rs_result rs_patch_s_run(rs_job_t *job)
{
rs_trace("running command %#04x", job->op);
@@ -137,23 +124,20 @@ static rs_result rs_patch_s_run(rs_job_t *job)
}
}
-
-/**
- * Called when trying to copy through literal data.
- */
+/** Called when trying to copy through literal data. */
static rs_result rs_patch_s_literal(rs_job_t *job)
{
- rs_long_t len = job->param1;
+ rs_long_t len = job->param1;
- rs_trace("LITERAL(len="FMT_LONG")", len);
+ rs_trace("LITERAL(len=" FMT_LONG ")", len);
if (len < 0) {
- rs_error("invalid length="FMT_LONG" on LITERAL command", len);
+ rs_error("invalid length=" FMT_LONG " on LITERAL command", len);
return RS_CORRUPT;
}
job->stats.lit_cmds++;
- job->stats.lit_bytes += len;
+ job->stats.lit_bytes += len;
job->stats.lit_cmdbytes += 1 + job->cmd->len_1;
rs_tube_copy(job, len);
@@ -162,25 +146,23 @@ static rs_result rs_patch_s_literal(rs_job_t *job)
return RS_RUNNING;
}
-
-
static rs_result rs_patch_s_copy(rs_job_t *job)
{
- rs_long_t where, len;
- rs_stats_t *stats;
+ rs_long_t where, len;
+ rs_stats_t *stats;
where = job->param1;
len = job->param2;
- rs_trace("COPY(where="FMT_LONG", len="FMT_LONG")", where, len);
+ rs_trace("COPY(where=" FMT_LONG ", len=" FMT_LONG ")", where, len);
if (len < 0) {
- rs_error("invalid length="FMT_LONG" on COPY command", len);
+ rs_error("invalid length=" FMT_LONG " on COPY command", len);
return RS_CORRUPT;
}
if (where < 0) {
- rs_error("invalid where="FMT_LONG" on COPY command", where);
+ rs_error("invalid where=" FMT_LONG " on COPY command", where);
return RS_CORRUPT;
}
@@ -197,36 +179,35 @@ static rs_result rs_patch_s_copy(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Called when we're executing a COPY command and waiting for all the
- * data to be retrieved from the callback.
- */
+/** Called when we're executing a COPY command and waiting for all the data to
+ * be retrieved from the callback. */
static rs_result rs_patch_s_copying(rs_job_t *job)
{
- rs_result result;
- size_t desired_len, len;
- void *ptr;
- rs_buffers_t *buffs = job->stream;
+ rs_result result;
+ size_t desired_len, len;
+ void *ptr;
+ rs_buffers_t *buffs = job->stream;
- /* copy only as much as will fit in the output buffer, so that we
- * don't have to block or store the input. */
- desired_len = len = (buffs->avail_out < job->basis_len) ? buffs->avail_out : job->basis_len;
+ /* copy only as much as will fit in the output buffer, so that we don't
+ have to block or store the input. */
+ desired_len = len =
+ (buffs->avail_out < job->basis_len) ? buffs->avail_out : job->basis_len;
if (!len)
return RS_BLOCKED;
- rs_trace("copy "FMT_SIZE" bytes from basis at offset "FMT_LONG"", len, job->basis_pos);
+ rs_trace("copy " FMT_SIZE " bytes from basis at offset " FMT_LONG "", len,
+ job->basis_pos);
ptr = buffs->next_out;
- result = (job->copy_cb)(job->copy_arg, job->basis_pos, &len, &ptr);
+ result = (job->copy_cb) (job->copy_arg, job->basis_pos, &len, &ptr);
if (result != RS_DONE)
return result;
else
rs_trace("copy callback returned %s", rs_strerror(result));
- rs_trace("got "FMT_SIZE" bytes back from basis callback", len);
+ rs_trace("got " FMT_SIZE " bytes back from basis callback", len);
if (len > desired_len) {
rs_trace("warning: copy_cb returned more than the requested length.");
@@ -251,34 +232,28 @@ static rs_result rs_patch_s_copying(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Called while we're trying to read the header of the patch.
- */
+/** Called while we're trying to read the header of the patch. */
static rs_result rs_patch_s_header(rs_job_t *job)
{
- int v;
+ int v;
rs_result result;
-
if ((result = rs_suck_n4(job, &v)) != RS_DONE)
return result;
if (v != RS_DELTA_MAGIC) {
- rs_error("got magic number %#x rather than expected value %#x", v, RS_DELTA_MAGIC);
+ rs_error("got magic number %#x rather than expected value %#x", v,
+ RS_DELTA_MAGIC);
return RS_BAD_MAGIC;
} else
rs_trace("got patch magic %#x", v);
-
job->statefn = rs_patch_s_cmdbyte;
return RS_RUNNING;
}
-
-rs_job_t *
-rs_patch_begin(rs_copy_cb *copy_cb, void *copy_arg)
+rs_job_t *rs_patch_begin(rs_copy_cb * copy_cb, void *copy_arg)
{
rs_job_t *job = rs_job_new("patch", rs_patch_s_header);
diff --git a/src/rdiff.c b/src/rdiff.c
index 40fe233..704695e 100644
--- a/src/rdiff.c
+++ b/src/rdiff.c
@@ -28,21 +28,19 @@
/** \file rdiff.c -- Command-line network-delta tool.
*
- * \todo Add a -z option to gzip/gunzip patches. This would be
- * somewhat useful, but more importantly a good test of the streaming
- * API. Also add -I for bzip2.
+ * \todo Add a -z option to gzip/gunzip patches. This would be somewhat
+ * useful, but more importantly a good test of the streaming API. Also add -I
+ * for bzip2.
*
* \todo If built with debug support and we have mcheck, then turn it on.
* (Optionally?)
*
- * \todo popt doesn't handle single dashes very well at the moment:
- * we'd like to use them as arguments to indicate stdin/stdout, but it
- * turns them into options. I sent a patch to the popt maintainers;
- * hopefully it will be fixed in the future.
+ * \todo popt doesn't handle single dashes very well at the moment: we'd like
+ * to use them as arguments to indicate stdin/stdout, but it turns them into
+ * options. I sent a patch to the popt maintainers; hopefully it will be fixed
+ * in the future.
*
- * \todo Add an option for delta to check whether the files are
- * identical.
- */
+ * \todo Add an option for delta to check whether the files are identical. */
#include "config.h"
@@ -53,11 +51,11 @@
#include <popt.h>
#ifdef HAVE_ZLIB_H
-#include <zlib.h>
+# include <zlib.h>
#endif
#ifdef HAVE_BZLIB_H
-#include <bzlib.h>
+# include <bzlib.h>
#endif
#include "librsync.h"
@@ -67,7 +65,6 @@
#include "isprefix.h"
#include "sumset.h"
-
#define PROGRAM "rdiff"
static size_t block_len = RS_DEFAULT_BLOCK_LEN;
@@ -76,8 +73,8 @@ static size_t strong_len = 0;
static int show_stats = 0;
static int bzip2_level = 0;
-static int gzip_level = 0;
-static int file_force = 0;
+static int gzip_level = 0;
+static int file_force = 0;
enum {
OPT_GZIP = 1069, OPT_BZIP2
@@ -87,33 +84,30 @@ extern int rs_roll_paranoia;
char *rs_hash_name;
const struct poptOption opts[] = {
- { "verbose", 'v', POPT_ARG_NONE, 0, 'v' },
- { "version", 'V', POPT_ARG_NONE, 0, 'V' },
- { "input-size", 'I', POPT_ARG_INT, &rs_inbuflen },
- { "output-size", 'O', POPT_ARG_INT, &rs_outbuflen },
- { "hash", 'H', POPT_ARG_STRING, &rs_hash_name },
- { "help", '?', POPT_ARG_NONE, 0, 'h' },
- { 0, 'h', POPT_ARG_NONE, 0, 'h' },
- { "block-size", 'b', POPT_ARG_INT, &block_len },
- { "sum-size", 'S', POPT_ARG_INT, &strong_len },
- { "statistics", 's', POPT_ARG_NONE, &show_stats },
- { "stats", 0, POPT_ARG_NONE, &show_stats },
- { "gzip", 'z', POPT_ARG_NONE, 0, OPT_GZIP },
- { "bzip2", 'i', POPT_ARG_NONE, 0, OPT_BZIP2 },
- { "force", 'f', POPT_ARG_NONE, &file_force },
- { "paranoia", 0, POPT_ARG_NONE, &rs_roll_paranoia },
- { 0 }
+ {"verbose", 'v', POPT_ARG_NONE, 0, 'v'},
+ {"version", 'V', POPT_ARG_NONE, 0, 'V'},
+ {"input-size", 'I', POPT_ARG_INT, &rs_inbuflen},
+ {"output-size", 'O', POPT_ARG_INT, &rs_outbuflen},
+ {"hash", 'H', POPT_ARG_STRING, &rs_hash_name},
+ {"help", '?', POPT_ARG_NONE, 0, 'h'},
+ {0, 'h', POPT_ARG_NONE, 0, 'h'},
+ {"block-size", 'b', POPT_ARG_INT, &block_len},
+ {"sum-size", 'S', POPT_ARG_INT, &strong_len},
+ {"statistics", 's', POPT_ARG_NONE, &show_stats},
+ {"stats", 0, POPT_ARG_NONE, &show_stats},
+ {"gzip", 'z', POPT_ARG_NONE, 0, OPT_GZIP},
+ {"bzip2", 'i', POPT_ARG_NONE, 0, OPT_BZIP2},
+ {"force", 'f', POPT_ARG_NONE, &file_force},
+ {"paranoia", 0, POPT_ARG_NONE, &rs_roll_paranoia},
+ {0}
};
-
static void rdiff_usage(const char *error)
{
- fprintf(stderr, "%s\n"
- "Try `%s --help' for more information.\n",
- error, PROGRAM);
+ fprintf(stderr, "%s\n" "Try `%s --help' for more information.\n", error,
+ PROGRAM);
}
-
static void rdiff_no_more_args(poptContext opcon)
{
if (poptGetArg(opcon)) {
@@ -122,20 +116,18 @@ static void rdiff_no_more_args(poptContext opcon)
}
}
-
static void bad_option(poptContext opcon, int error)
{
- fprintf(stderr, "%s: %s: %s",
- PROGRAM, poptStrerror(error), poptBadOption(opcon, 0));
+ fprintf(stderr, "%s: %s: %s", PROGRAM, poptStrerror(error),
+ poptBadOption(opcon, 0));
exit(RS_SYNTAX_ERROR);
}
-
-static void help(void) {
+static void help(void)
+{
printf("Usage: rdiff [OPTIONS] signature [BASIS [SIGNATURE]]\n"
" [OPTIONS] delta SIGNATURE [NEWFILE [DELTA]]\n"
- " [OPTIONS] patch BASIS [DELTA [NEWFILE]]\n"
- "\n"
+ " [OPTIONS] patch BASIS [DELTA [NEWFILE]]\n" "\n"
"Options:\n"
" -v, --verbose Trace internal processing\n"
" -V, --version Show program version\n"
@@ -148,28 +140,25 @@ static void help(void) {
" -b, --block-size=BYTES Signature block size\n"
" -S, --sum-size=BYTES Set signature strength\n"
" --paranoia Verify all rolling checksums\n"
- "IO options:\n"
- " -I, --input-size=BYTES Input buffer size\n"
+ "IO options:\n" " -I, --input-size=BYTES Input buffer size\n"
" -O, --output-size=BYTES Output buffer size\n"
" -z, --gzip[=LEVEL] gzip-compress deltas\n"
- " -i, --bzip2[=LEVEL] bzip2-compress deltas\n"
- );
+ " -i, --bzip2[=LEVEL] bzip2-compress deltas\n");
}
-
static void rdiff_show_version(void)
{
char const *bzlib = "", *zlib = "", *trace = "";
#if 0
/* Compression isn't implemented so don't mention it. */
-#ifdef HAVE_LIBZ
+# ifdef HAVE_LIBZ
zlib = ", gzip";
-#endif
+# endif
-#ifdef HAVE_LIBBZ2
+# ifdef HAVE_LIBBZ2
bzlib = ", bzip2";
-#endif
+# endif
#endif
#ifndef DO_RS_TRACE
@@ -179,22 +168,18 @@ static void rdiff_show_version(void)
printf("rdiff (%s)\n"
"Copyright (C) 1997-2016 by Martin Pool, Andrew Tridgell and others.\n"
"http://librsync.sourcefrog.net/\n"
- "Capabilities: %ld bit files%s%s%s\n"
- "\n"
+ "Capabilities: %ld bit files%s%s%s\n" "\n"
"librsync comes with NO WARRANTY, to the extent permitted by law.\n"
"You may redistribute copies of librsync under the terms of the GNU\n"
"Lesser General Public License. For more information about these\n"
- "matters, see the files named COPYING.\n",
- rs_librsync_version,
- (long) (8 * sizeof(rs_long_t)), zlib, bzlib, trace);
+ "matters, see the files named COPYING.\n", rs_librsync_version,
+ (long)(8 * sizeof(rs_long_t)), zlib, bzlib, trace);
}
-
-
static void rdiff_options(poptContext opcon)
{
- int c;
- char const *a;
+ int c;
+ char const *a;
while ((c = poptGetNextOpt(opcon)) != -1) {
switch (c) {
@@ -221,9 +206,9 @@ static void rdiff_options(poptContext opcon)
bzip2_level = l;
} else {
if (c == OPT_GZIP)
- gzip_level = -1; /* library default */
+ gzip_level = -1; /* library default */
else
- bzip2_level = 9; /* demand the best */
+ bzip2_level = 9; /* demand the best */
}
rs_error("sorry, compression is not really implemented yet");
exit(RS_UNIMPLEMENTED);
@@ -234,16 +219,13 @@ static void rdiff_options(poptContext opcon)
}
}
-
-/**
- * Generate signature from remaining command line arguments.
- */
+/** Generate signature from remaining command line arguments. */
static rs_result rdiff_sig(poptContext opcon)
{
- FILE *basis_file, *sig_file;
- rs_stats_t stats;
- rs_result result;
- rs_long_t sig_magic;
+ FILE *basis_file, *sig_file;
+ rs_stats_t stats;
+ rs_result result;
+ rs_long_t sig_magic;
basis_file = rs_file_open(poptGetArg(opcon), "rb", file_force);
sig_file = rs_file_open(poptGetArg(opcon), "wb", file_force);
@@ -254,9 +236,8 @@ static rs_result rdiff_sig(poptContext opcon)
sig_magic = RS_BLAKE2_SIG_MAGIC;
} else if (!strcmp(rs_hash_name, "md4")) {
/* By default, for compatibility with rdiff 0.9.8 and before, mdfour
- * sums are truncated to only 8 bytes, making them even weaker, but
- * making the signature file shorter.
- */
+ sums are truncated to only 8 bytes, making them even weaker, but
+ making the signature file shorter. */
if (!strong_len)
strong_len = 8;
sig_magic = RS_MD4_SIG_MAGIC;
@@ -265,8 +246,9 @@ static rs_result rdiff_sig(poptContext opcon)
return RS_PARAM_ERROR;
}
- result = rs_sig_file(basis_file, sig_file, block_len, strong_len,
- sig_magic, &stats);
+ result =
+ rs_sig_file(basis_file, sig_file, block_len, strong_len, sig_magic,
+ &stats);
rs_file_close(sig_file);
rs_file_close(basis_file);
@@ -279,14 +261,13 @@ static rs_result rdiff_sig(poptContext opcon)
return result;
}
-
static rs_result rdiff_delta(poptContext opcon)
{
- FILE *sig_file, *new_file, *delta_file;
- char const *sig_name;
- rs_result result;
- rs_signature_t *sumset;
- rs_stats_t stats;
+ FILE *sig_file, *new_file, *delta_file;
+ char const *sig_name;
+ rs_result result;
+ rs_signature_t *sumset;
+ rs_stats_t stats;
if (!(sig_name = poptGetArg(opcon))) {
rdiff_usage("Usage for delta: "
@@ -326,15 +307,13 @@ static rs_result rdiff_delta(poptContext opcon)
return result;
}
-
-
static rs_result rdiff_patch(poptContext opcon)
{
- /* patch BASIS [DELTA [NEWFILE]] */
- FILE *basis_file, *delta_file, *new_file;
- char const *basis_name;
- rs_stats_t stats;
- rs_result result;
+ /* patch BASIS [DELTA [NEWFILE]] */
+ FILE *basis_file, *delta_file, *new_file;
+ char const *basis_name;
+ rs_stats_t stats;
+ rs_result result;
if (!(basis_name = poptGetArg(opcon))) {
rdiff_usage("Usage for patch: "
@@ -344,7 +323,7 @@ static rs_result rdiff_patch(poptContext opcon)
basis_file = rs_file_open(basis_name, "rb", file_force);
delta_file = rs_file_open(poptGetArg(opcon), "rb", file_force);
- new_file = rs_file_open(poptGetArg(opcon), "wb", file_force);
+ new_file = rs_file_open(poptGetArg(opcon), "wb", file_force);
rdiff_no_more_args(opcon);
@@ -360,15 +339,12 @@ static rs_result rdiff_patch(poptContext opcon)
return result;
}
-
-
static rs_result rdiff_action(poptContext opcon)
{
- const char *action;
+ const char *action;
action = poptGetArg(opcon);
- if (!action)
- ;
+ if (!action) ;
else if (isprefix(action, "signature"))
return rdiff_sig(opcon);
else if (isprefix(action, "delta"))
@@ -376,22 +352,22 @@ static rs_result rdiff_action(poptContext opcon)
else if (isprefix(action, "patch"))
return rdiff_patch(opcon);
- rdiff_usage("rdiff: You must specify an action: `signature', `delta', or `patch'.");
+ rdiff_usage
+ ("rdiff: You must specify an action: `signature', `delta', or `patch'.");
return RS_SYNTAX_ERROR;
}
-
int main(const int argc, const char *argv[])
{
- poptContext opcon;
- rs_result result;
+ poptContext opcon;
+ rs_result result;
opcon = poptGetContext(PROGRAM, argc, argv, opts, 0);
rdiff_options(opcon);
result = rdiff_action(opcon);
if (result != RS_DONE)
- rs_log(RS_LOG_ERR|RS_LOG_NONAME, "%s", rs_strerror(result));
+ rs_log(RS_LOG_ERR | RS_LOG_NONAME, "%s", rs_strerror(result));
poptFreeContext(opcon);
return result;
diff --git a/src/readsums.c b/src/readsums.c
index a1d7fbb..7326714 100644
--- a/src/readsums.c
+++ b/src/readsums.c
@@ -37,32 +37,29 @@
#include "util.h"
#include "stream.h"
-
static rs_result rs_loadsig_s_weak(rs_job_t *job);
static rs_result rs_loadsig_s_strong(rs_job_t *job);
-/**
- * Add a just-read-in checksum pair to the signature block.
- */
+/** Add a just-read-in checksum pair to the signature block. */
static rs_result rs_loadsig_add_sum(rs_job_t *job, rs_strong_sum_t *strong)
{
- rs_signature_t *sig = job->signature;
+ rs_signature_t *sig = job->signature;
if (rs_trace_enabled()) {
char hexbuf[RS_MAX_STRONG_SUM_LENGTH * 2 + 2];
rs_hexify(hexbuf, strong, sig->strong_sum_len);
- rs_trace("got block: weak="FMT_WEAKSUM", strong=%s", job->weak_sig, hexbuf);
+ rs_trace("got block: weak=" FMT_WEAKSUM ", strong=%s", job->weak_sig,
+ hexbuf);
}
rs_signature_add_block(job->signature, job->weak_sig, strong);
job->stats.sig_blocks++;
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_weak(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE) {
if (result == RS_INPUT_ENDED) /* ending here is OK */
@@ -74,47 +71,45 @@ static rs_result rs_loadsig_s_weak(rs_job_t *job)
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_strong(rs_job_t *job)
{
- rs_result result;
- rs_strong_sum_t *strongsum;
+ rs_result result;
+ rs_strong_sum_t *strongsum;
- if ((result = rs_scoop_read(job, job->signature->strong_sum_len, (void **)&strongsum)) != RS_DONE)
+ if ((result =
+ rs_scoop_read(job, job->signature->strong_sum_len,
+ (void **)&strongsum)) != RS_DONE)
return result;
job->statefn = rs_loadsig_s_weak;
return rs_loadsig_add_sum(job, strongsum);
}
-
-
static rs_result rs_loadsig_s_stronglen(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE)
return result;
- if (l < 0 || l > RS_MAX_STRONG_SUM_LENGTH) {
+ if (l < 0 || l > RS_MAX_STRONG_SUM_LENGTH) {
rs_error("strong sum length %d is implausible", l);
return RS_CORRUPT;
}
rs_trace("got strong sum length %d", l);
job->sig_strong_len = l;
/* Initialize the signature. */
- if ((result = rs_signature_init(job->signature, job->sig_magic,
- job->sig_block_len, job->sig_strong_len,
- job->sig_fsize)) != RS_DONE)
+ if ((result =
+ rs_signature_init(job->signature, job->sig_magic, job->sig_block_len,
+ job->sig_strong_len, job->sig_fsize)) != RS_DONE)
return result;
job->statefn = rs_loadsig_s_weak;
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_blocklen(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE)
return result;
@@ -129,11 +124,10 @@ static rs_result rs_loadsig_s_blocklen(rs_job_t *job)
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_magic(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE)
return result;
@@ -143,7 +137,6 @@ static rs_result rs_loadsig_s_magic(rs_job_t *job)
return RS_RUNNING;
}
-
rs_job_t *rs_loadsig_begin(rs_signature_t **signature)
{
rs_job_t *job;
diff --git a/src/rollsum.h b/src/rollsum.h
index 4b3ceba..218e7a8 100644
--- a/src/rollsum.h
+++ b/src/rollsum.h
@@ -20,14 +20,14 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ROLLSUM_H_
-#define _ROLLSUM_H_
+# define _ROLLSUM_H_
-#include <stddef.h>
-#include <stdint.h>
+# include <stddef.h>
+# include <stdint.h>
-/* We should make this something other than zero to improve the
- * checksum algorithm: tridge suggests a prime number. */
-#define ROLLSUM_CHAR_OFFSET 31
+/* We should make this something other than zero to improve the checksum
+ algorithm: tridge suggests a prime number. */
+# define ROLLSUM_CHAR_OFFSET 31
/** The Rollsum struct type \private. */
typedef struct _Rollsum {
@@ -45,7 +45,8 @@ static inline void RollsumInit(Rollsum *sum)
sum->count = sum->s1 = sum->s2 = 0;
}
-static inline void RollsumRotate(Rollsum *sum, unsigned char out, unsigned char in)
+static inline void RollsumRotate(Rollsum *sum, unsigned char out,
+ unsigned char in)
{
sum->s1 += in - out;
sum->s2 += sum->s1 - sum->count * (out + ROLLSUM_CHAR_OFFSET);
diff --git a/src/scoop.c b/src/scoop.c
index 5c19ee5..61bd7b7 100644
--- a/src/scoop.c
+++ b/src/scoop.c
@@ -25,34 +25,32 @@
| -- Shihad, `The General Electric'.
*/
-/** \file scoop.c This file deals with readahead from caller-supplied
- * buffers.
+/** \file scoop.c This file deals with readahead from caller-supplied buffers.
*
* Many functions require a certain minimum amount of input to do their
- * processing. For example, to calculate a strong checksum of a block
- * we need at least a block of input.
- *
- * Since we put the buffers completely under the control of the caller,
- * we can't count on ever getting this much data all in one go. We
- * can't simply wait, because the caller might have a smaller buffer
- * than we require and so we'll never get it. For the same reason we
- * must always accept all the data we're given.
- *
- * So, stream input data that's required for readahead is put into a
- * special buffer, from which the caller can then read. It's
- * essentially like an internal pipe, which on any given read request
- * may or may not be able to actually supply the data.
- *
- * As a future optimization, we might try to take data directly from the
- * input buffer if there's already enough there.
- *
- * \todo We probably know a maximum amount of data that can be scooped
- * up, so we could just avoid dynamic allocation. However that can't
- * be fixed at compile time, because when generating a delta it needs
- * to be large enough to hold one full block. Perhaps we can set it
- * up when the job is allocated? It would be kind of nice to not do
- * any memory allocation after startup, as bzlib does this.
- */
+ * processing. For example, to calculate a strong checksum of a block we need
+ * at least a block of input.
+ *
+ * Since we put the buffers completely under the control of the caller, we
+ * can't count on ever getting this much data all in one go. We can't simply
+ * wait, because the caller might have a smaller buffer than we require and so
+ * we'll never get it. For the same reason we must always accept all the data
+ * we're given.
+ *
+ * So, stream input data that's required for readahead is put into a special
+ * buffer, from which the caller can then read. It's essentially like an
+ * internal pipe, which on any given read request may or may not be able to
+ * actually supply the data.
+ *
+ * As a future optimization, we might try to take data directly from the input
+ * buffer if there's already enough there.
+ *
+ * \todo We probably know a maximum amount of data that can be scooped up, so
+ * we could just avoid dynamic allocation. However that can't be fixed at
+ * compile time, because when generating a delta it needs to be large enough to
+ * hold one full block. Perhaps we can set it up when the job is allocated? It
+ * would be kind of nice to not do any memory allocation after startup, as
+ * bzlib does this. */
#include "config.h"
@@ -67,7 +65,6 @@
#include "trace.h"
#include "util.h"
-
/** Try to accept a from the input buffer to get LEN bytes in the scoop. */
void rs_scoop_input(rs_job_t *job, size_t len)
{
@@ -77,34 +74,35 @@ void rs_scoop_input(rs_job_t *job, size_t len)
assert(len > job->scoop_avail);
if (job->scoop_alloc < len) {
- /* Need to allocate a larger scoop.*/
+ /* Need to allocate a larger scoop. */
rs_byte_t *newbuf;
size_t newsize;
- for (newsize = 64; newsize < len; newsize <<= 1);
+ for (newsize = 64; newsize < len; newsize <<= 1) ;
newbuf = rs_alloc(newsize, "scoop buffer");
if (job->scoop_avail)
memcpy(newbuf, job->scoop_next, job->scoop_avail);
if (job->scoop_buf)
free(job->scoop_buf);
job->scoop_buf = job->scoop_next = newbuf;
- rs_trace("resized scoop buffer to "FMT_SIZE" bytes from "FMT_SIZE"", newsize, job->scoop_alloc);
+ rs_trace("resized scoop buffer to " FMT_SIZE " bytes from " FMT_SIZE "",
+ newsize, job->scoop_alloc);
job->scoop_alloc = newsize;
} else if (job->scoop_buf != job->scoop_next) {
/* Move existing data to the front of the scoop. */
- rs_trace("moving scoop "FMT_SIZE" bytes to reuse "FMT_SIZE" bytes",
+ rs_trace("moving scoop " FMT_SIZE " bytes to reuse " FMT_SIZE " bytes",
job->scoop_avail, (size_t)(job->scoop_next - job->scoop_buf));
memmove(job->scoop_buf, job->scoop_next, job->scoop_avail);
job->scoop_next = job->scoop_buf;
}
- /* take as much input as is available, to give up to LEN bytes
- * in the scoop. */
+ /* take as much input as is available, to give up to LEN bytes in the
+ scoop. */
tocopy = len - job->scoop_avail;
if (tocopy > stream->avail_in)
tocopy = stream->avail_in;
assert(tocopy + job->scoop_avail <= job->scoop_alloc);
memcpy(job->scoop_next + job->scoop_avail, stream->next_in, tocopy);
- rs_trace("accepted "FMT_SIZE" bytes from input to scoop", tocopy);
+ rs_trace("accepted " FMT_SIZE " bytes from input to scoop", tocopy);
job->scoop_avail += tocopy;
stream->next_in += tocopy;
stream->avail_in -= tocopy;
@@ -112,28 +110,27 @@ void rs_scoop_input(rs_job_t *job, size_t len)
/** Advance the input cursor forward \p len bytes.
*
- * This is used after doing readahead, when you decide you want to keep it.
- * \p len must be no more than the amount of available data, so you can't
- * cheat.
+ * This is used after doing readahead, when you decide you want to keep it. \p
+ * len must be no more than the amount of available data, so you can't cheat.
*
- * So when creating a delta, we require one block of readahead. But
- * after examining that block, we might decide to advance over all of
- * it (if there is a match), or just one byte (if not). */
+ * So when creating a delta, we require one block of readahead. But after
+ * examining that block, we might decide to advance over all of it (if there is
+ * a match), or just one byte (if not). */
void rs_scoop_advance(rs_job_t *job, size_t len)
{
rs_buffers_t *stream = job->stream;
- /* It never makes sense to advance over a mixture of bytes from
- * the scoop and input, because you couldn't possibly have looked
- * at them all at the same time. */
+ /* It never makes sense to advance over a mixture of bytes from the scoop
+ and input, because you couldn't possibly have looked at them all at the
+ same time. */
if (job->scoop_avail) {
/* reading from the scoop buffer */
- rs_trace("advance over "FMT_SIZE" bytes from scoop", len);
+ rs_trace("advance over " FMT_SIZE " bytes from scoop", len);
assert(len <= job->scoop_avail);
job->scoop_avail -= len;
job->scoop_next += len;
} else {
- rs_trace("advance over "FMT_SIZE" bytes from input buffer", len);
+ rs_trace("advance over " FMT_SIZE " bytes from input buffer", len);
assert(len <= stream->avail_in);
stream->avail_in -= len;
stream->next_in += len;
@@ -142,15 +139,14 @@ void rs_scoop_advance(rs_job_t *job, size_t len)
/** Read from scoop without advancing.
*
- * Ask for LEN bytes of input from the stream. If that much data is
- * available, then return a pointer to it in PTR, advance the stream
- * input pointer over the data, and return RS_DONE. If there's not
- * enough data, then accept whatever is there into a buffer, advance
- * over it, and return RS_BLOCKED.
+ * Ask for LEN bytes of input from the stream. If that much data is available,
+ * then return a pointer to it in PTR, advance the stream input pointer over
+ * the data, and return RS_DONE. If there's not enough data, then accept
+ * whatever is there into a buffer, advance over it, and return RS_BLOCKED.
*
- * The data is not actually removed from the input, so this function
- * lets you do readahead. If you want to keep any of the data, you
- * should also call rs_scoop_advance() to skip over it. */
+ * The data is not actually removed from the input, so this function lets you
+ * do readahead. If you want to keep any of the data, you should also call
+ * rs_scoop_advance() to skip over it. */
rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
{
rs_buffers_t *stream = job->stream;
@@ -159,16 +155,18 @@ rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
if (!job->scoop_avail && stream->avail_in >= len) {
/* The scoop is empty and there's enough data in the input. */
*ptr = stream->next_in;
- rs_trace("got "FMT_SIZE" bytes direct from input", len);
+ rs_trace("got " FMT_SIZE " bytes direct from input", len);
return RS_DONE;
} else if (job->scoop_avail < len && stream->avail_in) {
/* There is not enough data in the scoop. */
- rs_trace("scoop has less than "FMT_SIZE" bytes, scooping from "FMT_SIZE" input bytes", len, stream->avail_in);
+ rs_trace("scoop has less than " FMT_SIZE " bytes, scooping from "
+ FMT_SIZE " input bytes", len, stream->avail_in);
rs_scoop_input(job, len);
}
if (job->scoop_avail >= len) {
/* There is enough data in the scoop now. */
- rs_trace("scoop has at least "FMT_SIZE" bytes, this is enough", job->scoop_avail);
+ rs_trace("scoop has at least " FMT_SIZE " bytes, this is enough",
+ job->scoop_avail);
*ptr = job->scoop_next;
return RS_DONE;
} else if (stream->eof_in) {
@@ -184,12 +182,11 @@ rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
/** Read LEN bytes if possible, and remove them from the input scoop.
*
- * \param ptr will be updated to point to a read-only buffer holding
- * the data, if enough is available.
+ * \param ptr will be updated to point to a read-only buffer holding the data,
+ * if enough is available.
*
- * \return RS_DONE if there was enough data, RS_BLOCKED if there was
- * not enough data yet, or RS_INPUT_ENDED if there was not enough
- * data and at EOF. */
+ * \return RS_DONE if there was enough data, RS_BLOCKED if there was not enough
+ * data yet, or RS_INPUT_ENDED if there was not enough data and at EOF. */
rs_result rs_scoop_read(rs_job_t *job, size_t len, void **ptr)
{
rs_result result;
@@ -206,8 +203,8 @@ rs_result rs_scoop_read(rs_job_t *job, size_t len, void **ptr)
*
* \param **ptr will point at the available data.
*
- * \return RS_DONE if there was data, RS_INPUT_ENDED if there was no
- * data and at EOF, RS_BLOCKED if there was no data and not at EOF. */
+ * \return RS_DONE if there was data, RS_INPUT_ENDED if there was no data and
+ * at EOF, RS_BLOCKED if there was no data and not at EOF. */
rs_result rs_scoop_read_rest(rs_job_t *job, size_t *len, void **ptr)
{
rs_buffers_t *stream = job->stream;
diff --git a/src/stats.c b/src/stats.c
index f554f18..ee75153 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -27,31 +27,26 @@
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
+# include <sys/file.h>
#endif
#include <string.h>
#include "librsync.h"
#include "trace.h"
-int
-rs_log_stats(rs_stats_t const *stats)
+int rs_log_stats(rs_stats_t const *stats)
{
char buf[1000];
rs_format_stats(stats, buf, sizeof buf - 1);
- rs_log(RS_LOG_INFO|RS_LOG_NONAME, "%s", buf);
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME, "%s", buf);
return 0;
}
-
-
-char *
-rs_format_stats(rs_stats_t const * stats,
- char *buf, size_t size)
+char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size)
{
char const *op = stats->op;
int len, sec;
@@ -63,38 +58,46 @@ rs_format_stats(rs_stats_t const * stats,
len = snprintf(buf, size, "%s statistics: ", op);
if (stats->lit_cmds) {
- len += snprintf(buf+len, size-len,
- "literal[%d cmds, "FMT_LONG" bytes, "FMT_LONG" cmdbytes] ",
- stats->lit_cmds, stats->lit_bytes, stats->lit_cmdbytes);
+ len +=
+ snprintf(buf + len, size - len,
+ "literal[%d cmds, " FMT_LONG " bytes, " FMT_LONG
+ " cmdbytes] ", stats->lit_cmds, stats->lit_bytes,
+ stats->lit_cmdbytes);
}
if (stats->sig_cmds) {
- len += snprintf(buf+len, size-len,
- "in-place-signature["FMT_LONG" cmds, "FMT_LONG" bytes] ",
- stats->sig_cmds, stats->sig_bytes);
+ len +=
+ snprintf(buf + len, size - len,
+ "in-place-signature[" FMT_LONG " cmds, " FMT_LONG
+ " bytes] ", stats->sig_cmds, stats->sig_bytes);
}
if (stats->copy_cmds || stats->false_matches) {
- len += snprintf(buf+len, size-len,
- "copy["FMT_LONG" cmds, "FMT_LONG" bytes, "FMT_LONG" cmdbytes, %d false]",
- stats->copy_cmds, stats->copy_bytes, stats->copy_cmdbytes, stats->false_matches);
+ len +=
+ snprintf(buf + len, size - len,
+ "copy[" FMT_LONG " cmds, " FMT_LONG " bytes, " FMT_LONG
+ " cmdbytes, %d false]", stats->copy_cmds,
+ stats->copy_bytes, stats->copy_cmdbytes,
+ stats->false_matches);
}
-
if (stats->sig_blocks) {
- len += snprintf(buf+len, size-len,
- "signature["FMT_LONG" blocks, "FMT_SIZE" bytes per block]",
- stats->sig_blocks, stats->block_len);
+ len +=
+ snprintf(buf + len, size - len,
+ "signature[" FMT_LONG " blocks, " FMT_SIZE
+ " bytes per block]", stats->sig_blocks, stats->block_len);
}
sec = (stats->end - stats->start);
- if (sec == 0) sec = 1; // avoid division by zero
+ if (sec == 0)
+ sec = 1; // avoid division by zero
mbps_in = stats->in_bytes / 1e6 / sec;
mbps_out = stats->out_bytes / 1e6 / sec;
- len += snprintf(buf+len, size-len,
- " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]",
- (stats->in_bytes/1e6), mbps_in,
- (stats->out_bytes/1e6), mbps_out, sec);
+ len +=
+ snprintf(buf + len, size - len,
+ " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]",
+ (stats->in_bytes / 1e6), mbps_in, (stats->out_bytes / 1e6),
+ mbps_out, sec);
return buf;
}
diff --git a/src/stream.c b/src/stream.c
index 7e780b3..293b6c1 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -32,53 +32,49 @@
* See \sa scoop.c and \sa tube.c for related code for input and output
* respectively.
*
- * OK, so I'll admit IO here is a little complex. The most important
- * player here is the stream, which is an object for managing filter
- * operations. It has both input and output sides, both of which is
- * just a (pointer,len) pair into a buffer provided by the client.
- * The code controlling the stream handles however much data it wants,
- * and the client provides or accepts however much is convenient.
- *
- * At the same time as being friendly to the client, we also try to be
- * very friendly to the internal code. It wants to be able to ask for
- * arbitrary amounts of input or output and get it without having to
- * keep track of partial completion. So there are functions which
- * either complete, or queue whatever was not sent and return
- * RS_BLOCKED.
- *
- * The output buffer is a little more clever than simply a data
- * buffer. Instead it knows that we can send either literal data, or
- * data copied through from the input of the stream.
- *
- * In buf.c you will find functions that then map buffers onto stdio
- * files.
- *
- * So on return from an encoding function, either the input or the
- * output or possibly both will have no more bytes available.
- *
- * librsync never does IO or memory allocation, but relies on the
- * caller. This is very nice for integration, but means that we have
- * to be fairly flexible as to when we can `read' or `write' stuff
- * internally.
- *
- * librsync basically does two types of IO. It reads network integers
- * of various lengths which encode command and control information
- * such as versions and signatures. It also does bulk data transfer.
- *
- * IO of network integers is internally buffered, because higher
- * levels of the code need to see them transmitted atomically: it's no
- * good to read half of a uint32. So there is a small and fixed
- * length internal buffer which accumulates these. Unlike previous
- * versions of the library, we don't require that the caller hold the
- * start until the whole thing has arrived, which guarantees that we
- * can always make progress.
- *
- * On each call into a stream iterator, it should begin by trying to
- * flush output. This may well use up all the remaining stream space,
- * in which case nothing else can be done.
+ * OK, so I'll admit IO here is a little complex. The most important player
+ * here is the stream, which is an object for managing filter operations. It
+ * has both input and output sides, both of which is just a (pointer,len) pair
+ * into a buffer provided by the client. The code controlling the stream
+ * handles however much data it wants, and the client provides or accepts
+ * however much is convenient.
+ *
+ * At the same time as being friendly to the client, we also try to be very
+ * friendly to the internal code. It wants to be able to ask for arbitrary
+ * amounts of input or output and get it without having to keep track of
+ * partial completion. So there are functions which either complete, or queue
+ * whatever was not sent and return RS_BLOCKED.
+ *
+ * The output buffer is a little more clever than simply a data buffer.
+ * Instead it knows that we can send either literal data, or data copied
+ * through from the input of the stream.
+ *
+ * In buf.c you will find functions that then map buffers onto stdio files.
+ *
+ * So on return from an encoding function, either the input or the output or
+ * possibly both will have no more bytes available.
+ *
+ * librsync never does IO or memory allocation, but relies on the caller. This
+ * is very nice for integration, but means that we have to be fairly flexible
+ * as to when we can `read' or `write' stuff internally.
+ *
+ * librsync basically does two types of IO. It reads network integers of
+ * various lengths which encode command and control information such as
+ * versions and signatures. It also does bulk data transfer.
+ *
+ * IO of network integers is internally buffered, because higher levels of the
+ * code need to see them transmitted atomically: it's no good to read half of a
+ * uint32. So there is a small and fixed length internal buffer which
+ * accumulates these. Unlike previous versions of the library, we don't
+ * require that the caller hold the start until the whole thing has arrived,
+ * which guarantees that we can always make progress.
+ *
+ * On each call into a stream iterator, it should begin by trying to flush
+ * output. This may well use up all the remaining stream space, in which case
+ * nothing else can be done.
*
* \todo Kill this file and move the vestigial code remaining closer to where
- * it's used. */
+ * it's used. */
#include "config.h"
@@ -94,33 +90,33 @@
/** Copy up to \p max_len bytes from input of \b stream to its output.
*
- * \return the number of bytes actually copied, which may be less than
- * LEN if there is not enough space in one or the other stream.
+ * \return the number of bytes actually copied, which may be less than LEN if
+ * there is not enough space in one or the other stream.
*
* This always does the copy immediately. Most functions should call
- * rs_tube_copy() to cause the copy to happen gradually as space
- * becomes available.
- */
+ * rs_tube_copy() to cause the copy to happen gradually as space becomes
+ * available. */
int rs_buffers_copy(rs_buffers_t *stream, int max_len)
{
int len = max_len;
assert(len > 0);
- if ((unsigned) len > stream->avail_in) {
- rs_trace("copy limited to "FMT_SIZE" available input bytes", stream->avail_in);
+ if ((unsigned)len > stream->avail_in) {
+ rs_trace("copy limited to " FMT_SIZE " available input bytes",
+ stream->avail_in);
len = stream->avail_in;
}
-
- if ((unsigned) len > stream->avail_out) {
- rs_trace("copy limited to "FMT_SIZE" available output bytes", stream->avail_out);
+ if ((unsigned)len > stream->avail_out) {
+ rs_trace("copy limited to " FMT_SIZE " available output bytes",
+ stream->avail_out);
len = stream->avail_out;
}
if (!len)
return 0;
-/* rs_trace("stream copied chunk of %d bytes", len); */
+ /* rs_trace("stream copied chunk of %d bytes", len); */
memcpy(stream->next_out, stream->next_in, len);
@@ -135,11 +131,10 @@ int rs_buffers_copy(rs_buffers_t *stream, int max_len)
/** Assert input is empty or output is full.
*
- * Whenever a stream processing function exits, it should have done so
- * because it has either consumed all the input or has filled the
- * output buffer. This function checks that simple postcondition.
- */
+ * Whenever a stream processing function exits, it should have done so because
+ * it has either consumed all the input or has filled the output buffer. This
+ * function checks that simple postcondition. */
void rs_buffers_check_exit(rs_buffers_t const *stream)
{
- assert(stream->avail_in == 0 || stream->avail_out == 0);
+ assert(stream->avail_in == 0 || stream->avail_out == 0);
}
diff --git a/src/sumset.c b/src/sumset.c
index 7916bd3..155cdcc 100644
--- a/src/sumset.c
+++ b/src/sumset.c
@@ -36,11 +36,12 @@
const int RS_MD4_SUM_LENGTH = 16;
const int RS_BLAKE2_SUM_LENGTH = 32;
-static void rs_block_sig_init(rs_block_sig_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum, int strong_len)
+static void rs_block_sig_init(rs_block_sig_t *sig, rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum, int strong_len)
{
sig->weak_sum = weak_sum;
if (strong_sum)
- memcpy(sig->strong_sum, strong_sum, strong_len);
+ memcpy(sig->strong_sum, strong_sum, strong_len);
}
static inline unsigned rs_block_sig_hash(const rs_block_sig_t *sig)
@@ -55,26 +56,32 @@ typedef struct rs_block_match {
size_t len;
} rs_block_match_t;
-static void rs_block_match_init(rs_block_match_t *match, rs_signature_t *sig, rs_weak_sum_t weak_sum,
- rs_strong_sum_t *strong_sum, const void *buf, size_t len)
+static void rs_block_match_init(rs_block_match_t *match, rs_signature_t *sig,
+ rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum, const void *buf,
+ size_t len)
{
- rs_block_sig_init(&match->block_sig, weak_sum, strong_sum, sig->strong_sum_len);
+ rs_block_sig_init(&match->block_sig, weak_sum, strong_sum,
+ sig->strong_sum_len);
match->signature = sig;
match->buf = buf;
match->len = len;
}
-static inline int rs_block_match_cmp(rs_block_match_t *match, const rs_block_sig_t *block_sig)
+static inline int rs_block_match_cmp(rs_block_match_t *match,
+ const rs_block_sig_t *block_sig)
{
/* If buf is not NULL, the strong sum is yet to be calculated. */
if (match->buf) {
#ifndef HASHTABLE_NSTATS
match->signature->calc_strong_count++;
#endif
- rs_signature_calc_strong_sum(match->signature, match->buf, match->len, &(match->block_sig.strong_sum));
+ rs_signature_calc_strong_sum(match->signature, match->buf, match->len,
+ &(match->block_sig.strong_sum));
match->buf = NULL;
}
- return memcmp(&match->block_sig.strong_sum, &block_sig->strong_sum, match->signature->strong_sum_len);
+ return memcmp(&match->block_sig.strong_sum, &block_sig->strong_sum,
+ match->signature->strong_sum_len);
}
/* Instantiate hashtable for rs_block_sig and rs_block_match. */
@@ -86,24 +93,33 @@ static inline int rs_block_match_cmp(rs_block_match_t *match, const rs_block_sig
/* Get the size of a packed rs_block_sig_t. */
static inline size_t rs_block_sig_size(const rs_signature_t *sig)
{
- /* Round up to next multiple of sizeof(weak_sum) to align memory correctly. */
- return offsetof(rs_block_sig_t, strong_sum) + ((sig->strong_sum_len + sizeof(rs_weak_sum_t) - 1) /
- sizeof(rs_weak_sum_t)) * sizeof(rs_weak_sum_t);
+ /* Round up to next multiple of sizeof(weak_sum) to align memory correctly.
+ */
+ return offsetof(rs_block_sig_t,
+ strong_sum) + ((sig->strong_sum_len +
+ sizeof(rs_weak_sum_t)-
+ 1) / sizeof(rs_weak_sum_t)) *
+ sizeof(rs_weak_sum_t);
}
/* Get the pointer to the block_sig_t from a block index. */
-static inline rs_block_sig_t *rs_block_sig_ptr(const rs_signature_t *sig, int block_idx)
+static inline rs_block_sig_t *rs_block_sig_ptr(const rs_signature_t *sig,
+ int block_idx)
{
- return (rs_block_sig_t*)((char*)sig->block_sigs + block_idx * rs_block_sig_size(sig));
+ return (rs_block_sig_t *)((char *)sig->block_sigs +
+ block_idx * rs_block_sig_size(sig));
}
/* Get the index of a block from a block_sig_t pointer. */
-static inline int rs_block_sig_idx(const rs_signature_t *sig, rs_block_sig_t *block_sig)
+static inline int rs_block_sig_idx(const rs_signature_t *sig,
+ rs_block_sig_t *block_sig)
{
- return ((char *)block_sig - (char *)sig->block_sigs) / rs_block_sig_size(sig);
+ return ((char *)block_sig -
+ (char *)sig->block_sigs) / rs_block_sig_size(sig);
}
-rs_result rs_signature_init(rs_signature_t *sig, int magic, int block_len, int strong_len, rs_long_t sig_fsize)
+rs_result rs_signature_init(rs_signature_t *sig, int magic, int block_len,
+ int strong_len, rs_long_t sig_fsize)
{
int max_strong_len;
@@ -131,10 +147,13 @@ rs_result rs_signature_init(rs_signature_t *sig, int magic, int block_len, int s
sig->strong_sum_len = strong_len;
sig->count = 0;
/* Calculate the number of blocks if we have the signature file size. */
- /* Magic+header is 12 bytes, each block thereafter is 4 bytes weak_sum+strong_sum_len bytes */
+ /* Magic+header is 12 bytes, each block thereafter is 4 bytes
+ weak_sum+strong_sum_len bytes */
sig->size = (int)(sig_fsize ? (sig_fsize - 12) / (4 + strong_len) : 0);
if (sig->size)
- sig->block_sigs = rs_alloc(sig->size * rs_block_sig_size(sig), "signature->block_sigs");
+ sig->block_sigs =
+ rs_alloc(sig->size * rs_block_sig_size(sig),
+ "signature->block_sigs");
else
sig->block_sigs = NULL;
sig->hashtable = NULL;
@@ -151,20 +170,25 @@ void rs_signature_done(rs_signature_t *sig)
rs_bzero(sig, sizeof(*sig));
}
-rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum)
+rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig,
+ rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum)
{
rs_signature_check(sig);
/* If block_sigs is full, allocate more space. */
if (sig->count == sig->size) {
sig->size = sig->size ? sig->size * 2 : 16;
- sig->block_sigs = rs_realloc(sig->block_sigs, sig->size * rs_block_sig_size(sig), "signature->block_sigs");
+ sig->block_sigs =
+ rs_realloc(sig->block_sigs, sig->size * rs_block_sig_size(sig),
+ "signature->block_sigs");
}
rs_block_sig_t *b = rs_block_sig_ptr(sig, sig->count++);
rs_block_sig_init(b, weak_sum, strong_sum, sig->strong_sum_len);
return b;
}
-rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum, void const *buf, size_t len)
+rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum,
+ void const *buf, size_t len)
{
rs_block_match_t m;
rs_block_sig_t *b;
@@ -182,15 +206,15 @@ void rs_signature_log_stats(rs_signature_t const *sig)
#ifndef HASHTABLE_NSTATS
hashtable_t *t = sig->hashtable;
- rs_log(RS_LOG_INFO|RS_LOG_NONAME,
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME,
"match statistics: signature[%ld searches, %ld (%.3f%%) matches, "
"%ld (%.3fx) weak sum compares, %ld (%.3f%%) strong sum compares, "
- "%ld (%.3f%%) strong sum calcs]",
- t->find_count,
- t->match_count, 100.0 * (double)t->match_count / t->find_count,
- t->hashcmp_count, (double)t->hashcmp_count / t->find_count,
- t->entrycmp_count, 100.0 * (double)t->entrycmp_count / t->find_count,
- sig->calc_strong_count, 100.0 * (double)sig->calc_strong_count / t->find_count);
+ "%ld (%.3f%%) strong sum calcs]", t->find_count, t->match_count,
+ 100.0 * (double)t->match_count / t->find_count, t->hashcmp_count,
+ (double)t->hashcmp_count / t->find_count, t->entrycmp_count,
+ 100.0 * (double)t->entrycmp_count / t->find_count,
+ sig->calc_strong_count,
+ 100.0 * (double)sig->calc_strong_count / t->find_count);
#endif
}
@@ -226,12 +250,15 @@ void rs_sumset_dump(rs_signature_t const *sums)
rs_block_sig_t *b;
char strong_hex[RS_MAX_STRONG_SUM_LENGTH * 3];
- rs_log(RS_LOG_INFO|RS_LOG_NONAME, "sumset info: magic=%#x, block_len=%d, block_num=%d",
- sums->magic, sums->block_len, sums->count);
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME,
+ "sumset info: magic=%#x, block_len=%d, block_num=%d", sums->magic,
+ sums->block_len, sums->count);
for (i = 0; i < sums->count; i++) {
b = rs_block_sig_ptr(sums, i);
rs_hexify(strong_hex, b->strong_sum, sums->strong_sum_len);
- rs_log(RS_LOG_INFO|RS_LOG_NONAME, "sum %6d: weak="FMT_WEAKSUM", strong=%s", i, b->weak_sum, strong_hex);
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME,
+ "sum %6d: weak=" FMT_WEAKSUM ", strong=%s", i, b->weak_sum,
+ strong_hex);
}
}
diff --git a/src/sumset.h b/src/sumset.h
index 9b9e03a..32c559e 100644
--- a/src/sumset.h
+++ b/src/sumset.h
@@ -32,8 +32,8 @@ typedef struct rs_block_sig {
/** Signature of a whole file.
*
- * This includes the all the block sums generated for a file and
- * datastructures for fast matching against them. */
+ * This includes the all the block sums generated for a file and datastructures
+ * for fast matching against them. */
struct rs_signature {
int magic; /**< The signature magic value. */
int block_len; /**< The block length. */
@@ -62,16 +62,20 @@ struct rs_signature {
*
* \param sig_fsize signature file size to preallocate required storage for.
* Use 0 if size is unknown. */
-rs_result rs_signature_init(rs_signature_t *sig, int magic, int block_len, int strong_len, rs_long_t sig_fsize);
+rs_result rs_signature_init(rs_signature_t *sig, int magic, int block_len,
+ int strong_len, rs_long_t sig_fsize);
/** Destroy an rs_signature instance. */
void rs_signature_done(rs_signature_t *sig);
/** Add a block to an rs_signature instance. */
-rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum);
+rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig,
+ rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum);
/** Find a matching block offset in a signature. */
-rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum, void const *buf, size_t len);
+rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum,
+ void const *buf, size_t len);
/** Log the rs_signature_find_match() stats. */
void rs_signature_log_stats(rs_signature_t const *sig);
@@ -90,7 +94,8 @@ void rs_signature_log_stats(rs_signature_t const *sig);
} while (0)
/** Calculate the strong sum of a buffer. */
-static inline void rs_signature_calc_strong_sum(rs_signature_t const *sig, void const *buf, size_t len,
+static inline void rs_signature_calc_strong_sum(rs_signature_t const *sig,
+ void const *buf, size_t len,
rs_strong_sum_t *sum)
{
if (sig->magic == RS_BLAKE2_SIG_MAGIC) {
diff --git a/src/trace.c b/src/trace.c
index 96ea1cb..3c8206e 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -28,18 +28,18 @@
/** \file trace.c logging and debugging output.
*
- * \todo Have a bit set in the log level that says not to include the
- * function name. */
+ * \todo Have a bit set in the log level that says not to include the function
+ * name. */
#include "config.h"
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#else
-#define STDERR_FILENO 2
+# define STDERR_FILENO 2
#endif
#include <stdio.h>
#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
+# include <sys/file.h>
#endif
#include <string.h>
#include <errno.h>
@@ -51,7 +51,7 @@
#include "util.h"
#include "trace.h"
-rs_trace_fn_t *rs_trace_impl = rs_trace_stderr;
+rs_trace_fn_t *rs_trace_impl = rs_trace_stderr;
int rs_trace_level = RS_LOG_INFO;
@@ -71,85 +71,74 @@ static const char *rs_severities[] = {
/** Set the destination of trace information.
*
- * The callback scheme allows for use within applications that may
- * have their own particular ways of reporting errors: log files for a
- * web server, perhaps, and an error dialog for a browser.
+ * The callback scheme allows for use within applications that may have their
+ * own particular ways of reporting errors: log files for a web server,
+ * perhaps, and an error dialog for a browser.
*
- * \todo Do we really need such fine-grained control, or just yes/no
- * tracing?
- */
-void
-rs_trace_to(rs_trace_fn_t * new_impl)
+ * \todo Do we really need such fine-grained control, or just yes/no tracing? */
+void rs_trace_to(rs_trace_fn_t *new_impl)
{
rs_trace_impl = new_impl;
}
-void
-rs_trace_set_level(rs_loglevel level)
+void rs_trace_set_level(rs_loglevel level)
{
rs_trace_level = level;
}
-static void
-rs_log_va(int flags, char const *fn, char const *fmt, va_list va)
+static void rs_log_va(int flags, char const *fn, char const *fmt, va_list va)
{
int level = flags & RS_LOG_PRIMASK;
if (rs_trace_impl && level <= rs_trace_level) {
- char buf[1000];
- char full_buf[1000];
+ char buf[1000];
+ char full_buf[1000];
vsnprintf(buf, sizeof buf - 1, fmt, va);
if (flags & RS_LOG_NONAME) {
- snprintf(full_buf, sizeof full_buf - 1,
- "%s: %s%s\n", MY_NAME, rs_severities[level], buf);
+ snprintf(full_buf, sizeof full_buf - 1, "%s: %s%s\n", MY_NAME,
+ rs_severities[level], buf);
} else {
- snprintf(full_buf, sizeof full_buf - 1,
- "%s: %s(%s) %s\n", MY_NAME, rs_severities[level], fn, buf);
+ snprintf(full_buf, sizeof full_buf - 1, "%s: %s(%s) %s\n", MY_NAME,
+ rs_severities[level], fn, buf);
}
rs_trace_impl(level, full_buf);
}
}
-/* Called by a macro, used on platforms where we can't determine the
- calling function name. */
-void
-rs_log0_nofn(int level, char const *fmt, ...)
+/* Called by a macro, used on platforms where we can't determine the calling
+ function name. */
+void rs_log0_nofn(int level, char const *fmt, ...)
{
- va_list va;
+ va_list va;
va_start(va, fmt);
rs_log_va(level, PACKAGE, fmt, va);
va_end(va);
}
-/* Called by a macro that prepends the calling function name,
- etc. */
-void
-rs_log0(int level, char const *fn, char const *fmt, ...)
+/* Called by a macro that prepends the calling function name, etc. */
+void rs_log0(int level, char const *fn, char const *fmt, ...)
{
- va_list va;
+ va_list va;
va_start(va, fmt);
rs_log_va(level, fn, fmt, va);
va_end(va);
}
-void
-rs_trace_stderr(rs_loglevel UNUSED(level), char const *msg)
+void rs_trace_stderr(rs_loglevel UNUSED(level), char const *msg)
{
/* NOTE NO TRAILING NUL */
write(STDERR_FILENO, msg, strlen(msg));
}
-/* This is called directly if the machine doesn't allow varargs
- macros. */
-void
-rs_fatal0(char const *s, ...)
+/* This is called directly if the machine doesn't allow varargs macros. */
+void rs_fatal0(char const *s, ...)
{
- va_list va;
+ va_list va;
va_start(va, s);
rs_log_va(RS_LOG_CRIT, PACKAGE, s, va);
@@ -157,38 +146,33 @@ rs_fatal0(char const *s, ...)
abort();
}
-/* This is called directly if the machine doesn't allow varargs
- macros. */
-void
-rs_error0(char const *s, ...)
+/* This is called directly if the machine doesn't allow varargs macros. */
+void rs_error0(char const *s, ...)
{
- va_list va;
+ va_list va;
va_start(va, s);
rs_log_va(RS_LOG_ERR, PACKAGE, s, va);
va_end(va);
}
-/* This is called directly if the machine doesn't allow varargs
- macros. */
-void
-rs_trace0(char const *s, ...)
+/* This is called directly if the machine doesn't allow varargs macros. */
+void rs_trace0(char const *s, ...)
{
#ifdef DO_RS_TRACE
- va_list va;
+ va_list va;
va_start(va, s);
rs_log_va(RS_LOG_DEBUG, PACKAGE, s, va);
va_end(va);
-#endif /* !DO_RS_TRACE */
+#endif /* !DO_RS_TRACE */
}
-int
-rs_supports_trace(void)
+int rs_supports_trace(void)
{
#ifdef DO_RS_TRACE
return 1;
#else
return 0;
-#endif /* !DO_RS_TRACE */
+#endif /* !DO_RS_TRACE */
}
diff --git a/src/trace.h b/src/trace.h
index 590e86b..726bfed 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -27,9 +27,9 @@
*
* fatal terminates the whole process.
*
- * \todo A function like perror that includes strerror output. Apache
- * does this by adding flags as well as the severity level which say
- * whether such information should be included. */
+ * \todo A function like perror that includes strerror output. Apache does
+ * this by adding flags as well as the severity level which say whether such
+ * information should be included. */
#include <inttypes.h>
/* Printf format patters for standard librsync types. */
@@ -37,50 +37,46 @@
#define FMT_WEAKSUM "%08"PRIx32
/* Old MSVC compilers don't support "%zu" and have "%Iu" instead. */
#ifdef HAVE_PRINTF_Z
-#define FMT_SIZE "%zu"
+# define FMT_SIZE "%zu"
#else
-#define FMT_SIZE "%Iu"
+# define FMT_SIZE "%Iu"
#endif
-
#if defined(__clang__) || defined(__GNUC__)
-/** \todo Also look for the C9X predefined identifier `_function', or
- * whatever it's called. */
+/** \todo Also look for the C9X predefined identifier `_function', or whatever
+ * it's called. */
void rs_log0(int level, char const *fn, char const *fmt, ...)
__attribute__ ((format(printf, 3, 4)));
-#ifdef DO_RS_TRACE
-# define rs_trace(fmt, arg...) \
- do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg); \
+# ifdef DO_RS_TRACE
+# define rs_trace(fmt, arg...) \
+ do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg); \
} while (0)
-#else
-# define rs_trace(fmt, arg...)
-#endif /* !DO_RS_TRACE */
+# else
+# define rs_trace(fmt, arg...)
+# endif /* !DO_RS_TRACE */
-#define rs_log(l, s, str...) do { \
- rs_log0((l), __FUNCTION__, (s) , ##str); \
+# define rs_log(l, s, str...) do { \
+ rs_log0((l), __FUNCTION__, (s) , ##str); \
} while (0)
-
-#define rs_error(s, str...) do { \
- rs_log0(RS_LOG_ERR, __FUNCTION__, (s) , ##str); \
+# define rs_error(s, str...) do { \
+ rs_log0(RS_LOG_ERR, __FUNCTION__, (s) , ##str); \
} while (0)
-
-#define rs_fatal(s, str...) do { \
- rs_log0(RS_LOG_CRIT, __FUNCTION__, \
- (s) , ##str); \
- abort(); \
+# define rs_fatal(s, str...) do { \
+ rs_log0(RS_LOG_CRIT, __FUNCTION__, \
+ (s) , ##str); \
+ abort(); \
} while (0)
-
-#else /* !__GNUC__ */
+#else /* !__GNUC__ */
# define rs_trace rs_trace0
# define rs_fatal rs_fatal0
# define rs_error rs_error0
# define rs_log rs_log0_nofn
-#endif /* !__GNUC__ */
+#endif /* !__GNUC__ */
void rs_trace0(char const *s, ...);
void rs_fatal0(char const *s, ...);
@@ -89,18 +85,14 @@ void rs_log0(int level, char const *fn, char const *fmt, ...);
void rs_log0_nofn(int level, char const *fmt, ...);
enum {
- RS_LOG_PRIMASK = 7, /**< Mask to extract priority
- part. \internal */
+ RS_LOG_PRIMASK = 7, /**< Mask to extract priority part. \internal */
- RS_LOG_NONAME = 8 /**< \b Don't show function name in
- message. */
+ RS_LOG_NONAME = 8 /**< \b Don't show function name in message. */
};
-
/** \macro rs_trace_enabled()
*
- * Call this before putting too much effort into generating trace
- * messages. */
+ * Call this before putting too much effort into generating trace messages. */
extern int rs_trace_level;
diff --git a/src/tube.c b/src/tube.c
index c10c999..6ed4662 100644
--- a/src/tube.c
+++ b/src/tube.c
@@ -32,24 +32,23 @@
/** \file tube.c A somewhat elastic but fairly small buffer for data passing
* through a stream.
*
- * In most cases the iter can adjust to send just as much data will
- * fit. In some cases that would be too complicated, because it has
- * to transmit an integer or something similar. So in that case we
- * stick whatever won't fit into a small buffer.
+ * In most cases the iter can adjust to send just as much data will fit. In
+ * some cases that would be too complicated, because it has to transmit an
+ * integer or something similar. So in that case we stick whatever won't fit
+ * into a small buffer.
*
- * A tube can contain some literal data to go out (typically command
- * bytes), and also an instruction to copy data from the stream's
- * input or from some other location. Both literal data and a copy
- * command can be queued at the same time, but only in that order and
- * at most one of each.
+ * A tube can contain some literal data to go out (typically command bytes),
+ * and also an instruction to copy data from the stream's input or from some
+ * other location. Both literal data and a copy command can be queued at the
+ * same time, but only in that order and at most one of each.
*
- * \todo As an optimization, write it directly to the stream if
- * possible. But for simplicity don't do that yet.
+ * \todo As an optimization, write it directly to the stream if possible. But
+ * for simplicity don't do that yet.
*
- * \todo I think our current copy code will lock up if the application
- * only ever calls us with either input or output buffers, and not
- * both. So I guess in that case we might need to copy into some
- * temporary buffer space, and then back out again later. */
+ * \todo I think our current copy code will lock up if the application only
+ * ever calls us with either input or output buffers, and not both. So I guess
+ * in that case we might need to copy into some temporary buffer space, and
+ * then back out again later. */
#include "config.h"
@@ -73,7 +72,7 @@ static void rs_tube_catchup_write(rs_job_t *job)
assert(len > 0);
assert(len > 0);
- if ((size_t) len > stream->avail_out)
+ if ((size_t)len > stream->avail_out)
len = stream->avail_out;
if (!stream->avail_out) {
@@ -86,7 +85,8 @@ static void rs_tube_catchup_write(rs_job_t *job)
stream->avail_out -= len;
remain = job->write_len - len;
- rs_trace("transmitted %d write bytes from tube, %d remain to be sent", len, remain);
+ rs_trace("transmitted %d write bytes from tube, %d remain to be sent", len,
+ remain);
if (remain > 0) {
/* Still something left in the tube... */
@@ -101,13 +101,13 @@ static void rs_tube_catchup_write(rs_job_t *job)
/** Execute a copy command, taking data from the scoop.
*
* \sa rs_tube_catchup_copy() */
-static void
-rs_tube_copy_from_scoop(rs_job_t *job)
+static void rs_tube_copy_from_scoop(rs_job_t *job)
{
- size_t this_len;
+ size_t this_len;
rs_buffers_t *stream = job->stream;
- this_len = job->copy_len < job->scoop_avail ? job->copy_len : job->scoop_avail;
+ this_len =
+ job->copy_len < job->scoop_avail ? job->copy_len : job->scoop_avail;
if (this_len > stream->avail_out) {
this_len = stream->avail_out;
}
@@ -121,16 +121,15 @@ rs_tube_copy_from_scoop(rs_job_t *job)
job->copy_len -= this_len;
- rs_trace("caught up on "FMT_SIZE" copied bytes from scoop, "FMT_SIZE" remain there, "FMT_LONG" remain to be copied",
- this_len, job->scoop_avail, job->copy_len);
+ rs_trace("caught up on " FMT_SIZE " copied bytes from scoop, " FMT_SIZE
+ " remain there, " FMT_LONG " remain to be copied", this_len,
+ job->scoop_avail, job->copy_len);
}
-
/** Catch up on an outstanding copy command.
*
- * Takes data from the scoop, and the input (in that order), and
- * writes as much as will fit to the output, up to the limit of the
- * outstanding copy. */
+ * Takes data from the scoop, and the input (in that order), and writes as much
+ * as will fit to the output, up to the limit of the outstanding copy. */
static void rs_tube_catchup_copy(rs_job_t *job)
{
assert(job->write_len == 0);
@@ -144,11 +143,11 @@ static void rs_tube_catchup_copy(rs_job_t *job)
if (job->copy_len && !job->scoop_avail) {
size_t this_copy = rs_buffers_copy(job->stream, job->copy_len);
job->copy_len -= this_copy;
- rs_trace("copied "FMT_SIZE" bytes from input buffer, "FMT_LONG" remain to be copied", this_copy, job->copy_len);
+ rs_trace("copied " FMT_SIZE " bytes from input buffer, " FMT_LONG
+ " remain to be copied", this_copy, job->copy_len);
}
}
-
/** Put whatever will fit from the tube into the output of the stream.
*
* \return RS_DONE if the tube is now empty and ready to accept another
@@ -164,8 +163,10 @@ int rs_tube_catchup(rs_job_t *job)
if (job->copy_len) {
rs_tube_catchup_copy(job);
if (job->copy_len) {
- if (job->stream->eof_in && !job->stream->avail_in && !job->scoop_avail) {
- rs_error("reached end of file while copying literal data through buffers");
+ if (job->stream->eof_in && !job->stream->avail_in
+ && !job->scoop_avail) {
+ rs_error
+ ("reached end of file while copying literal data through buffers");
return RS_INPUT_ENDED;
}
return RS_BLOCKED;
@@ -174,30 +175,25 @@ int rs_tube_catchup(rs_job_t *job)
return RS_DONE;
}
-
/* Check whether there is data in the tube waiting to go out.
- *
- * \return true if the previous command has finished doing all its
- * output. */
+
+ \return true if the previous command has finished doing all its output. */
int rs_tube_is_idle(rs_job_t const *job)
{
return job->write_len == 0 && job->copy_len == 0;
}
-
-/** Queue up a request to copy through \p len bytes from the input to
- * the output of the stream.
+/** Queue up a request to copy through \p len bytes from the input to the
+ * output of the stream.
*
- * The data is copied from the scoop (if there is anything there) or
- * from the input, on the next call to rs_tube_write().
+ * The data is copied from the scoop (if there is anything there) or from the
+ * input, on the next call to rs_tube_write().
*
- * We can only accept this request if there is no copy command already
- * pending.
+ * We can only accept this request if there is no copy command already pending.
*
- * \todo Try to do the copy immediately, and return a result. Then,
- * people can try to continue if possible. Is this really required?
- * Callers can just go out and back in again after flushing the
- * tube. */
+ * \todo Try to do the copy immediately, and return a result. Then, people can
+ * try to continue if possible. Is this really required? Callers can just go
+ * out and back in again after flushing the tube. */
void rs_tube_copy(rs_job_t *job, int len)
{
assert(job->copy_len == 0);
@@ -205,21 +201,19 @@ void rs_tube_copy(rs_job_t *job, int len)
job->copy_len = len;
}
-
/** Push some data into the tube for storage.
*
- * The tube's never supposed to get very big, so this will just pop loudly if you do
- * that.
+ * The tube's never supposed to get very big, so this will just pop loudly if
+ * you do that.
*
- * We can't accept write data if there's already a copy command in the
- * tube, because the write data comes out first. */
-void
-rs_tube_write(rs_job_t *job, const void *buf, size_t len)
+ * We can't accept write data if there's already a copy command in the tube,
+ * because the write data comes out first. */
+void rs_tube_write(rs_job_t *job, const void *buf, size_t len)
{
assert(job->copy_len == 0);
if (len > sizeof(job->write_buf) - job->write_len) {
- rs_fatal("tube popped when trying to write "FMT_SIZE" bytes!", len);
+ rs_fatal("tube popped when trying to write " FMT_SIZE " bytes!", len);
}
memcpy(job->write_buf + job->write_len, buf, len);
diff --git a/src/util.c b/src/util.c
index aea862a..ff7ba65 100644
--- a/src/util.c
+++ b/src/util.c
@@ -31,17 +31,14 @@
#include "util.h"
#include "trace.h"
-void
-rs_bzero(void *buf, size_t size)
+void rs_bzero(void *buf, size_t size)
{
memset(buf, 0, size);
}
-
-void *
-rs_alloc_struct0(size_t size, char const *name)
+void *rs_alloc_struct0(size_t size, char const *name)
{
- void *p;
+ void *p;
if (!(p = malloc(size))) {
rs_fatal("couldn't allocate instance of %s", name);
@@ -50,12 +47,9 @@ rs_alloc_struct0(size_t size, char const *name)
return p;
}
-
-
-void *
-rs_alloc(size_t size, char const *name)
+void *rs_alloc(size_t size, char const *name)
{
- void *p;
+ void *p;
if (!(p = malloc(size))) {
rs_fatal("couldn't allocate instance of %s", name);
@@ -64,14 +58,12 @@ rs_alloc(size_t size, char const *name)
return p;
}
-
-void *
-rs_realloc(void *ptr, size_t size, char const *name)
+void *rs_realloc(void *ptr, size_t size, char const *name)
{
void *p;
if (!(p = realloc(ptr, size))) {
- rs_fatal("couldn't reallocate instance of %s", name);
- }
- return p;
+ rs_fatal("couldn't reallocate instance of %s", name);
+ }
+ return p;
}
diff --git a/src/util.h b/src/util.h
index 8e3fe6a..e7b3b43 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,42 +1,39 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
* Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-void * rs_alloc(size_t size, char const *name);
-void * rs_realloc(void *ptr, size_t size, char const *name);
+void *rs_alloc(size_t size, char const *name);
+void *rs_realloc(void *ptr, size_t size, char const *name);
void *rs_alloc_struct0(size_t size, char const *name);
void rs_bzero(void *buf, size_t size);
-/**
- * Allocate and zero-fill an instance of TYPE.
- */
+/** Allocate and zero-fill an instance of TYPE. */
#define rs_alloc_struct(type) \
((type *) rs_alloc_struct0(sizeof(type), #type))
-
#ifdef __GNUC__
# define UNUSED(x) x __attribute__((unused))
#elif defined(__LCLINT__) || defined(S_SPLINT_S)
# define UNUSED(x) /*@unused@*/ x
-#else /* !__GNUC__ && !__LCLINT__ */
+#else /* !__GNUC__ && !__LCLINT__ */
# define UNUSED(x) x
-#endif /* !__GNUC__ && !__LCLINT__ */
+#endif /* !__GNUC__ && !__LCLINT__ */
diff --git a/src/version.c b/src/version.c
index 6e2299f..ec6b8a9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -21,5 +21,4 @@
#include "config.h"
-
char const rs_librsync_version[] = (PACKAGE " " VERSION);
diff --git a/src/whole.c b/src/whole.c
index d4dfde0..8e098ca 100644
--- a/src/whole.c
+++ b/src/whole.c
@@ -32,7 +32,7 @@
#include <assert.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#include <stdio.h>
#include <string.h>
@@ -48,18 +48,14 @@
#include "whole.h"
#include "util.h"
-
-/**
- * Whole file IO buffer sizes.
- */
+/** Whole file IO buffer sizes. */
int rs_inbuflen = 0, rs_outbuflen = 0;
-
/** Run a job continuously, with input to/from the two specified files.
*
- * The job should already be set up, and must be freed by the caller
- * after return. If rs_inbuflen or rs_outbuflen are set, they will override
- * the inbuflen and outbuflen arguments.
+ * The job should already be set up, and must be freed by the caller after
+ * return. If rs_inbuflen or rs_outbuflen are set, they will override the
+ * inbuflen and outbuflen arguments.
*
* \param in_file - input file, or NULL if there is no input.
*
@@ -69,14 +65,13 @@ int rs_inbuflen = 0, rs_outbuflen = 0;
*
* \param outbuflen - recommended output buffer size to use.
*
- * \return RS_DONE if the job completed, or otherwise an error result.
- */
-rs_result
-rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int outbuflen)
+ * \return RS_DONE if the job completed, or otherwise an error result. */
+rs_result rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file,
+ int inbuflen, int outbuflen)
{
- rs_buffers_t buf;
- rs_result result;
- rs_filebuf_t *in_fb = NULL, *out_fb = NULL;
+ rs_buffers_t buf;
+ rs_result result;
+ rs_filebuf_t *in_fb = NULL, *out_fb = NULL;
/* Override buffer sizes if rs_inbuflen or rs_outbuflen are set. */
inbuflen = rs_inbuflen ? rs_inbuflen : inbuflen;
@@ -85,9 +80,9 @@ rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int out
in_fb = rs_filebuf_new(in_file, inbuflen);
if (out_file)
out_fb = rs_filebuf_new(out_file, outbuflen);
- result = rs_job_drive(job, &buf,
- in_fb ? rs_infilebuf_fill : NULL, in_fb,
- out_fb ? rs_outfilebuf_drain : NULL, out_fb);
+ result =
+ rs_job_drive(job, &buf, in_fb ? rs_infilebuf_fill : NULL, in_fb,
+ out_fb ? rs_outfilebuf_drain : NULL, out_fb);
if (in_fb)
rs_filebuf_free(in_fb);
if (out_fb)
@@ -95,20 +90,17 @@ rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int out
return result;
}
-
-
-rs_result
-rs_sig_file(FILE *old_file, FILE *sig_file, size_t new_block_len,
- size_t strong_len,
- rs_magic_number sig_magic,
- rs_stats_t *stats)
+rs_result rs_sig_file(FILE *old_file, FILE *sig_file, size_t new_block_len,
+ size_t strong_len, rs_magic_number sig_magic,
+ rs_stats_t *stats)
{
- rs_job_t *job;
- rs_result r;
+ rs_job_t *job;
+ rs_result r;
job = rs_sig_begin(new_block_len, strong_len, sig_magic);
/* Size inbuf for 4 blocks, outbuf for header + 4 blocksums. */
- r = rs_whole_run(job, old_file, sig_file, 4 * new_block_len, 12 + 4*(4 + strong_len));
+ r = rs_whole_run(job, old_file, sig_file, 4 * new_block_len,
+ 12 + 4 * (4 + strong_len));
if (stats)
memcpy(stats, &job->stats, sizeof *stats);
rs_job_free(job);
@@ -116,12 +108,11 @@ rs_sig_file(FILE *old_file, FILE *sig_file, size_t new_block_len,
return r;
}
-
-rs_result
-rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset, rs_stats_t *stats)
+rs_result rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset,
+ rs_stats_t *stats)
{
- rs_job_t *job;
- rs_result r;
+ rs_job_t *job;
+ rs_result r;
job = rs_loadsig_begin(sumset);
/* Estimate a number of signatures by file size */
@@ -135,33 +126,31 @@ rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset, rs_stats_t *stats)
return r;
}
-
-rs_result
-rs_delta_file(rs_signature_t *sig, FILE *new_file, FILE *delta_file,
- rs_stats_t *stats)
+rs_result rs_delta_file(rs_signature_t *sig, FILE *new_file, FILE *delta_file,
+ rs_stats_t *stats)
{
- rs_job_t *job;
- rs_result r;
+ rs_job_t *job;
+ rs_result r;
job = rs_delta_begin(sig);
/* Size inbuf for 1 block, outbuf for literal cmd + 4 blocks. */
- r = rs_whole_run(job, new_file, delta_file, sig->block_len, 10 + 4*sig->block_len);
+ r = rs_whole_run(job, new_file, delta_file, sig->block_len,
+ 10 + 4 * sig->block_len);
if (stats)
memcpy(stats, &job->stats, sizeof *stats);
rs_job_free(job);
return r;
}
-
rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file,
rs_stats_t *stats)
{
- rs_job_t *job;
- rs_result r;
+ rs_job_t *job;
+ rs_result r;
job = rs_patch_begin(rs_file_copy_cb, basis_file);
/* Default size inbuf and outbuf 64K. */
- r = rs_whole_run(job, delta_file, new_file, 64*1024, 64*1024);
+ r = rs_whole_run(job, delta_file, new_file, 64 * 1024, 64 * 1024);
if (stats)
memcpy(stats, &job->stats, sizeof *stats);
rs_job_free(job);
diff --git a/src/whole.h b/src/whole.h
index eea49e0..945f568 100644
--- a/src/whole.h
+++ b/src/whole.h
@@ -19,5 +19,5 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-rs_result rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int outbuflen);
+rs_result rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file,
+ int inbuflen, int outbuflen);