\doxysubsection{whole.\+c}
\label{whole_8c_source}\index{whole.c@{whole.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * librsync -\/-\/ the library for network deltas}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright 2000, 2001, 2014, 2015 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00006 \textcolor{comment}{ *}}
\DoxyCodeLine{00007 \textcolor{comment}{ * This program is free software; you can redistribute it and/or}}
\DoxyCodeLine{00008 \textcolor{comment}{ * modify it under the terms of the GNU Lesser General Public License}}
\DoxyCodeLine{00009 \textcolor{comment}{ * as published by the Free Software Foundation; either version 2.1 of}}
\DoxyCodeLine{00010 \textcolor{comment}{ * the License, or (at your option) any later version.}}
\DoxyCodeLine{00011 \textcolor{comment}{ *}}
\DoxyCodeLine{00012 \textcolor{comment}{ * This program is distributed in the hope that it will be useful, but}}
\DoxyCodeLine{00013 \textcolor{comment}{ * WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00014 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU}}
\DoxyCodeLine{00015 \textcolor{comment}{ * Lesser General Public License for more details.}}
\DoxyCodeLine{00016 \textcolor{comment}{ *}}
\DoxyCodeLine{00017 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public}}
\DoxyCodeLine{00018 \textcolor{comment}{ * License along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00019 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00020 \textcolor{comment}{ */}}
\DoxyCodeLine{00021 }
\DoxyCodeLine{00022                               \textcolor{comment}{/*=}}
\DoxyCodeLine{00023 \textcolor{comment}{                               | Is it possible that software is not}}
\DoxyCodeLine{00024 \textcolor{comment}{                               | like anything else, that it is meant}}
\DoxyCodeLine{00025 \textcolor{comment}{                               | to be discarded: that the whole point}}
\DoxyCodeLine{00026 \textcolor{comment}{                               | is to always see it as a soap bubble?}}
\DoxyCodeLine{00027 \textcolor{comment}{                               |        -\/-\/ Alan Perlis}}
\DoxyCodeLine{00028 \textcolor{comment}{                               */}}
\DoxyCodeLine{00029 }
\DoxyCodeLine{00030 \textcolor{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00031 \textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{00032 \textcolor{preprocessor}{\#include <string.h>}}
\DoxyCodeLine{00033 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00034 \textcolor{preprocessor}{\#include "{}whole.h"{}}}
\DoxyCodeLine{00035 \textcolor{preprocessor}{\#include "{}sumset.h"{}}}
\DoxyCodeLine{00036 \textcolor{preprocessor}{\#include "{}job.h"{}}}
\DoxyCodeLine{00037 \textcolor{preprocessor}{\#include "{}buf.h"{}}}
\DoxyCodeLine{00038 \textcolor{preprocessor}{\#include "{}librsync\_export.h"{}}}
\DoxyCodeLine{00039 \textcolor{comment}{}}
\DoxyCodeLine{00040 \textcolor{comment}{/** Whole file IO buffer sizes. */}}
\DoxyCodeLine{00041 LIBRSYNC\_EXPORT \textcolor{keywordtype}{int} rs\_inbuflen = 0, rs\_outbuflen = 0;}
\DoxyCodeLine{00042 }
\DoxyCodeLine{00043 rs\_result rs\_whole\_run(rs\_job\_t *job, FILE *in\_file, FILE *out\_file,}
\DoxyCodeLine{00044                        \textcolor{keywordtype}{int} inbuflen, \textcolor{keywordtype}{int} outbuflen)}
\DoxyCodeLine{00045 \{}
\DoxyCodeLine{00046     rs\_buffers\_t buf;}
\DoxyCodeLine{00047     rs\_result result;}
\DoxyCodeLine{00048     rs\_filebuf\_t *in\_fb = NULL, *out\_fb = NULL;}
\DoxyCodeLine{00049 }
\DoxyCodeLine{00050     \textcolor{comment}{/* Override buffer sizes if rs\_inbuflen or rs\_outbuflen are set. */}}
\DoxyCodeLine{00051     inbuflen = rs\_inbuflen ? rs\_inbuflen : inbuflen;}
\DoxyCodeLine{00052     outbuflen = rs\_outbuflen ? rs\_outbuflen : outbuflen;}
\DoxyCodeLine{00053     \textcolor{keywordflow}{if} (in\_file)}
\DoxyCodeLine{00054         in\_fb = rs\_filebuf\_new(in\_file, inbuflen);}
\DoxyCodeLine{00055     \textcolor{keywordflow}{if} (out\_file)}
\DoxyCodeLine{00056         out\_fb = rs\_filebuf\_new(out\_file, outbuflen);}
\DoxyCodeLine{00057     result =}
\DoxyCodeLine{00058         rs\_job\_drive(job, \&buf, in\_fb ? rs\_infilebuf\_fill : NULL, in\_fb,}
\DoxyCodeLine{00059                      out\_fb ? rs\_outfilebuf\_drain : NULL, out\_fb);}
\DoxyCodeLine{00060     \textcolor{keywordflow}{if} (in\_fb)}
\DoxyCodeLine{00061         rs\_filebuf\_free(in\_fb);}
\DoxyCodeLine{00062     \textcolor{keywordflow}{if} (out\_fb)}
\DoxyCodeLine{00063         rs\_filebuf\_free(out\_fb);}
\DoxyCodeLine{00064     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00065 \}}
\DoxyCodeLine{00066 }
\DoxyCodeLine{00067 rs\_result rs\_sig\_file(FILE *old\_file, FILE *sig\_file, \textcolor{keywordtype}{size\_t} block\_len,}
\DoxyCodeLine{00068                       \textcolor{keywordtype}{size\_t} strong\_len, rs\_magic\_number sig\_magic,}
\DoxyCodeLine{00069                       rs\_stats\_t *stats)}
\DoxyCodeLine{00070 \{}
\DoxyCodeLine{00071     rs\_job\_t *job;}
\DoxyCodeLine{00072     rs\_result r;}
\DoxyCodeLine{00073     rs\_long\_t old\_fsize = rs\_file\_size(old\_file);}
\DoxyCodeLine{00074 }
\DoxyCodeLine{00075     \textcolor{keywordflow}{if} ((r =}
\DoxyCodeLine{00076          rs\_sig\_args(old\_fsize, \&sig\_magic, \&block\_len,}
\DoxyCodeLine{00077                      \&strong\_len)) != RS\_DONE)}
\DoxyCodeLine{00078         \textcolor{keywordflow}{return} r;}
\DoxyCodeLine{00079     job = rs\_sig\_begin(block\_len, strong\_len, sig\_magic);}
\DoxyCodeLine{00080     \textcolor{comment}{/* Size inbuf for 4 blocks, outbuf for header + 4 blocksums. */}}
\DoxyCodeLine{00081     r = rs\_whole\_run(job, old\_file, sig\_file, 4 * (\textcolor{keywordtype}{int})block\_len,}
\DoxyCodeLine{00082                      12 + 4 * (4 + (\textcolor{keywordtype}{int})strong\_len));}
\DoxyCodeLine{00083     \textcolor{keywordflow}{if} (stats)}
\DoxyCodeLine{00084         memcpy(stats, \&job-\/>stats, \textcolor{keyword}{sizeof} *stats);}
\DoxyCodeLine{00085     rs\_job\_free(job);}
\DoxyCodeLine{00086 }
\DoxyCodeLine{00087     \textcolor{keywordflow}{return} r;}
\DoxyCodeLine{00088 \}}
\DoxyCodeLine{00089 }
\DoxyCodeLine{00090 rs\_result rs\_loadsig\_file(FILE *sig\_file, rs\_signature\_t **sumset,}
\DoxyCodeLine{00091                           rs\_stats\_t *stats)}
\DoxyCodeLine{00092 \{}
\DoxyCodeLine{00093     rs\_job\_t *job;}
\DoxyCodeLine{00094     rs\_result r;}
\DoxyCodeLine{00095 }
\DoxyCodeLine{00096     job = rs\_loadsig\_begin(sumset);}
\DoxyCodeLine{00097     \textcolor{comment}{/* Set filesize used to estimate signature size. */}}
\DoxyCodeLine{00098     job-\/>sig\_fsize = rs\_file\_size(sig\_file);}
\DoxyCodeLine{00099     \textcolor{comment}{/* Size inbuf for 1024x 16 byte blocksums. */}}
\DoxyCodeLine{00100     r = rs\_whole\_run(job, sig\_file, NULL, 1024 * 16, 0);}
\DoxyCodeLine{00101     \textcolor{keywordflow}{if} (stats)}
\DoxyCodeLine{00102         memcpy(stats, \&job-\/>stats, \textcolor{keyword}{sizeof} *stats);}
\DoxyCodeLine{00103     rs\_job\_free(job);}
\DoxyCodeLine{00104 }
\DoxyCodeLine{00105     \textcolor{keywordflow}{return} r;}
\DoxyCodeLine{00106 \}}
\DoxyCodeLine{00107 }
\DoxyCodeLine{00108 rs\_result rs\_delta\_file(rs\_signature\_t *sig, FILE *new\_file, FILE *delta\_file,}
\DoxyCodeLine{00109                         rs\_stats\_t *stats)}
\DoxyCodeLine{00110 \{}
\DoxyCodeLine{00111     rs\_job\_t *job;}
\DoxyCodeLine{00112     rs\_result r;}
\DoxyCodeLine{00113 }
\DoxyCodeLine{00114     job = rs\_delta\_begin(sig);}
\DoxyCodeLine{00115     \textcolor{comment}{/* Size inbuf for 4*(CMD + 1 block), outbuf for 4*CMD. */}}
\DoxyCodeLine{00116     r = rs\_whole\_run(job, new\_file, delta\_file,}
\DoxyCodeLine{00117                      4 * (MAX\_DELTA\_CMD + sig-\/>block\_len), 4 * MAX\_DELTA\_CMD);}
\DoxyCodeLine{00118     \textcolor{keywordflow}{if} (stats)}
\DoxyCodeLine{00119         memcpy(stats, \&job-\/>stats, \textcolor{keyword}{sizeof} *stats);}
\DoxyCodeLine{00120     rs\_job\_free(job);}
\DoxyCodeLine{00121     \textcolor{keywordflow}{return} r;}
\DoxyCodeLine{00122 \}}
\DoxyCodeLine{00123 }
\DoxyCodeLine{00124 rs\_result rs\_patch\_file(FILE *basis\_file, FILE *delta\_file, FILE *new\_file,}
\DoxyCodeLine{00125                         rs\_stats\_t *stats)}
\DoxyCodeLine{00126 \{}
\DoxyCodeLine{00127     rs\_job\_t *job;}
\DoxyCodeLine{00128     rs\_result r;}
\DoxyCodeLine{00129 }
\DoxyCodeLine{00130     job = rs\_patch\_begin(rs\_file\_copy\_cb, basis\_file);}
\DoxyCodeLine{00131     \textcolor{comment}{/* Default size inbuf 1*CMD and outbuf 4*CMD. */}}
\DoxyCodeLine{00132     r = rs\_whole\_run(job, delta\_file, new\_file, MAX\_DELTA\_CMD,}
\DoxyCodeLine{00133                      4 * MAX\_DELTA\_CMD);}
\DoxyCodeLine{00134     \textcolor{keywordflow}{if} (stats)}
\DoxyCodeLine{00135         memcpy(stats, \&job-\/>stats, \textcolor{keyword}{sizeof} *stats);}
\DoxyCodeLine{00136     rs\_job\_free(job);}
\DoxyCodeLine{00137     \textcolor{keywordflow}{return} r;}
\DoxyCodeLine{00138 \}}

\end{DoxyCode}
