Backup deleted files when using --delete and --backup. Based on a
[rsync/rsync.git] / syscall.c
CommitLineData
31e12522
AT
1/*
2 Copyright (C) Andrew Tridgell 1998
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/
18
19/*
20 syscall wrappers to ensure that nothing gets done in dry_run mode
21 */
22
23#include "rsync.h"
24
25extern int dry_run;
f0fca04e
AT
26extern int read_only;
27
28#define CHECK_RO if (read_only) {errno = EROFS; return -1;}
31e12522
AT
29
30int do_unlink(char *fname)
31{
32 if (dry_run) return 0;
f0fca04e 33 CHECK_RO
31e12522
AT
34 return unlink(fname);
35}
36
37int do_symlink(char *fname1, char *fname2)
38{
39 if (dry_run) return 0;
f0fca04e 40 CHECK_RO
31e12522
AT
41 return symlink(fname1, fname2);
42}
43
f92ef572 44#if HAVE_LINK
31e12522
AT
45int do_link(char *fname1, char *fname2)
46{
47 if (dry_run) return 0;
f0fca04e 48 CHECK_RO
31e12522
AT
49 return link(fname1, fname2);
50}
f92ef572 51#endif
31e12522 52
7308bd66
AT
53int do_lchown(const char *path, uid_t owner, gid_t group)
54{
55 if (dry_run) return 0;
f0fca04e 56 CHECK_RO
7308bd66
AT
57 return lchown(path, owner, group);
58}
59
f92ef572 60#if HAVE_MKNOD
31e12522
AT
61int do_mknod(char *pathname, mode_t mode, dev_t dev)
62{
63 if (dry_run) return 0;
f0fca04e 64 CHECK_RO
31e12522
AT
65 return mknod(pathname, mode, dev);
66}
f92ef572 67#endif
31e12522
AT
68
69int do_rmdir(char *pathname)
70{
71 if (dry_run) return 0;
f0fca04e 72 CHECK_RO
31e12522
AT
73 return rmdir(pathname);
74}
75
76int do_open(char *pathname, int flags, mode_t mode)
77{
78 if (dry_run) return -1;
f0fca04e 79 CHECK_RO
31e12522
AT
80 return open(pathname, flags, mode);
81}
7308bd66 82
f92ef572 83#if HAVE_CHMOD
7308bd66
AT
84int do_chmod(const char *path, mode_t mode)
85{
86 if (dry_run) return 0;
f0fca04e 87 CHECK_RO
7308bd66
AT
88 return chmod(path, mode);
89}
f92ef572 90#endif
1b2d733a
AT
91
92int do_rename(char *fname1, char *fname2)
93{
94 if (dry_run) return 0;
f0fca04e 95 CHECK_RO
1b2d733a
AT
96 return rename(fname1, fname2);
97}
98
99int do_mkdir(char *fname, mode_t mode)
100{
101 if (dry_run) return 0;
f0fca04e 102 CHECK_RO
1b2d733a
AT
103 return mkdir(fname, mode);
104}
105
106char *do_mktemp(char *template)
107{
108 if (dry_run) return NULL;
f0fca04e 109 if (read_only) {errno = EROFS; return NULL;}
1b2d733a
AT
110 return mktemp(template);
111}
bcacc18b
AT
112
113int do_stat(const char *fname, STRUCT_STAT *st)
114{
115#if HAVE_OFF64_T
116 return stat64(fname, st);
117#else
118 return stat(fname, st);
119#endif
120}
121
efb2f6bf 122#if SUPPORT_LINKS
bcacc18b
AT
123int do_lstat(const char *fname, STRUCT_STAT *st)
124{
125#if HAVE_OFF64_T
126 return lstat64(fname, st);
127#else
128 return lstat(fname, st);
129#endif
130}
efb2f6bf 131#endif
bcacc18b
AT
132
133int do_fstat(int fd, STRUCT_STAT *st)
134{
135#if HAVE_OFF64_T
136 return fstat64(fd, st);
137#else
138 return fstat(fd, st);
139#endif
140}
73233f0f
AT
141
142OFF_T do_lseek(int fd, OFF_T offset, int whence)
143{
144#if HAVE_OFF64_T
f28ee65b 145 off64_t lseek64();
73233f0f
AT
146 return lseek64(fd, offset, whence);
147#else
148 return lseek(fd, offset, whence);
149#endif
150}
d6e6ecbd 151
bb0f7089 152#ifdef USE_MMAP
754d120c
AT
153void *do_mmap(void *start, int len, int prot, int flags, int fd, OFF_T offset)
154{
155#if HAVE_OFF64_T
156 return mmap64(start, len, prot, flags, fd, offset);
157#else
158 return mmap(start, len, prot, flags, fd, offset);
159#endif
160}
161#endif
162
d6e6ecbd
AT
163char *d_name(struct dirent *di)
164{
59503278
AT
165#if HAVE_BROKEN_READDIR
166 return (di->d_name - 2);
167#else
d6e6ecbd 168 return di->d_name;
59503278 169#endif
d6e6ecbd 170}