added SIGPIPE catch
[rsync/rsync.git] / rsync.h
CommitLineData
c627d613
AT
1/*
2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#define BLOCK_SIZE 700
21#define RSYNC_RSH_ENV "RSYNC_RSH"
22#define RSYNC_RSH "rsh"
23#define RSYNC_NAME "rsync"
24#define BACKUP_SUFFIX "~"
25
26/* update this if you make incompatible changes */
27#define PROTOCOL_VERSION 9
28
29/* block size to write files in */
30#define WRITE_BLOCK_SIZE (32*1024)
31
58d433ab
AT
32#define BLOCKING_TIMEOUT 10
33
c627d613
AT
34#include "config.h"
35
36#include <sys/types.h>
37#ifdef HAVE_UNISTD_H
38#include <unistd.h>
39#endif
40#include <stdio.h>
41
42#ifdef HAVE_SYS_PARAM_H
43#include <sys/param.h>
44#endif
45
46#ifdef STDC_HEADERS
47# include <stdlib.h>
48# include <string.h>
49#endif
50
51#ifdef HAVE_COMPAT_H
52#include <compat.h>
53#endif
54
55#ifdef HAVE_MALLOC_H
56#include <malloc.h>
57#endif
58
59#ifdef TIME_WITH_SYS_TIME
60#include <sys/time.h>
61#include <time.h>
62#else
63#ifdef HAVE_SYS_TIME_H
64#include <sys/time.h>
65#else
66#include <time.h>
67#endif
68#endif
69
70#ifdef HAVE_FCNTL_H
71#include <fcntl.h>
72#else
73#ifdef HAVE_SYS_FCNTL_H
74#include <sys/fcntl.h>
75#endif
76#endif
77
78#include <sys/stat.h>
79
94481d91
AT
80#ifdef HAVE_SYS_IOCTL_H
81#include <sys/ioctl.h>
82#endif
83
84#ifdef HAVE_SYS_FILIO_H
85#include <sys/filio.h>
86#endif
87
c627d613
AT
88#include <signal.h>
89#ifdef HAVE_SYS_WAIT_H
90#include <sys/wait.h>
91#endif
92#ifdef HAVE_CTYPE_H
93#include <ctype.h>
94#endif
95#ifdef HAVE_GRP_H
96#include <grp.h>
97#endif
98#include <errno.h>
99
100#include <sys/mman.h>
101#ifdef HAVE_UTIME_H
102#include <utime.h>
103#endif
104
105#ifdef HAVE_FNMATCH
106#include <fnmatch.h>
107#else
108#include "lib/fnmatch.h"
109#endif
110
111#ifdef HAVE_GETOPT_LONG
112#include <getopt.h>
113#else
114#include "lib/getopt.h"
115#endif
116
117
118#ifndef S_ISLNK
119#define S_ISLNK(mode) (((mode) & S_IFLNK) == S_IFLNK)
120#endif
121
122#ifndef uchar
123#define uchar unsigned char
124#endif
125
126#ifndef int32
127#if (SIZEOF_INT == 4)
128#define int32 int
129#elif (SIZEOF_LONG == 4)
130#define int32 long
131#elif (SIZEOF_SHORT == 4)
132#define int32 short
133#endif
134#endif
135
136#ifndef uint32
137#define uint32 unsigned int32
138#endif
139
140
141#ifndef MIN
142#define MIN(a,b) ((a)<(b)?(a):(b))
143#endif
144
145#ifndef MAX
146#define MAX(a,b) ((a)>(b)?(a):(b))
147#endif
148
149/* the length of the md4 checksum */
150#define SUM_LENGTH 16
151
152#ifndef MAXPATHLEN
153#define MAXPATHLEN 1024
154#endif
155
156struct file_struct {
157 time_t modtime;
158 off_t length;
159 mode_t mode;
160 dev_t dev;
161 uid_t uid;
162 gid_t gid;
163 char *name;
164 char *dir;
165 char *link;
166 char sum[SUM_LENGTH];
167};
168
169struct file_list {
170 int count;
171 int malloced;
172 struct file_struct *files;
173};
174
175struct sum_buf {
176 off_t offset; /* offset in file of this chunk */
177 int len; /* length of chunk of file */
178 int i; /* index of this chunk */
179 uint32 sum1; /* simple checksum */
180 char sum2[SUM_LENGTH]; /* md4 checksum */
181};
182
183struct sum_struct {
184 off_t flength; /* total file length */
185 int count; /* how many chunks */
186 int remainder; /* flength % block_length */
187 int n; /* block_length */
188 struct sum_buf *sums; /* points to info for each chunk */
189};
190
191
192#include "byteorder.h"
193#include "version.h"
194#include "proto.h"
195#include "md4.h"
196
197#if !HAVE_STRERROR
198extern char *sys_errlist[];
199#define strerror(i) sys_errlist[i]
200#endif
201
202#ifndef HAVE_STRCHR
203# define strchr index
204# define strrchr rindex
205#endif
206
207#if HAVE_DIRENT_H
208# include <dirent.h>
209#else
210# define dirent direct
211# if HAVE_SYS_NDIR_H
212# include <sys/ndir.h>
213# endif
214# if HAVE_SYS_DIR_H
215# include <sys/dir.h>
216# endif
217# if HAVE_NDIR_H
218# include <ndir.h>
219# endif
220#endif
221
222#ifndef HAVE_ERRNO_DECL
223extern int errno;
224#endif
225
226#ifndef HAVE_BCOPY
227#define bcopy(src,dest,n) memcpy(dest,src,n)
228#endif
229
230#ifndef HAVE_BZERO
231#define bzero(buf,n) memset(buf,0,n)
232#endif
233
234#define SUPPORT_LINKS (HAVE_READLINK && defined(S_ISLNK))
235
236#if !SUPPORT_LINKS
237#define lstat stat
238#endif
ac1eb754
AT
239
240#define SIGNAL_CAST (RETSIGTYPE (*)())
720b47f2
AT
241
242#ifndef EWOULDBLOCK
243#define EWOULDBLOCK EAGAIN
244#endif