Commit | Line | Data |
---|---|---|
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 | ||
25 | extern int dry_run; | |
f0fca04e | 26 | extern int read_only; |
2b086e03 | 27 | extern int list_only; |
f0fca04e | 28 | |
2b086e03 | 29 | #define CHECK_RO if (read_only || list_only) {errno = EROFS; return -1;} |
31e12522 AT |
30 | |
31 | int do_unlink(char *fname) | |
32 | { | |
33 | if (dry_run) return 0; | |
f0fca04e | 34 | CHECK_RO |
31e12522 AT |
35 | return unlink(fname); |
36 | } | |
37 | ||
38 | int do_symlink(char *fname1, char *fname2) | |
39 | { | |
40 | if (dry_run) return 0; | |
f0fca04e | 41 | CHECK_RO |
31e12522 AT |
42 | return symlink(fname1, fname2); |
43 | } | |
44 | ||
f92ef572 | 45 | #if HAVE_LINK |
31e12522 AT |
46 | int do_link(char *fname1, char *fname2) |
47 | { | |
48 | if (dry_run) return 0; | |
f0fca04e | 49 | CHECK_RO |
31e12522 AT |
50 | return link(fname1, fname2); |
51 | } | |
f92ef572 | 52 | #endif |
31e12522 | 53 | |
7308bd66 AT |
54 | int do_lchown(const char *path, uid_t owner, gid_t group) |
55 | { | |
56 | if (dry_run) return 0; | |
f0fca04e | 57 | CHECK_RO |
7308bd66 AT |
58 | return lchown(path, owner, group); |
59 | } | |
60 | ||
f92ef572 | 61 | #if HAVE_MKNOD |
31e12522 AT |
62 | int do_mknod(char *pathname, mode_t mode, dev_t dev) |
63 | { | |
64 | if (dry_run) return 0; | |
f0fca04e | 65 | CHECK_RO |
31e12522 AT |
66 | return mknod(pathname, mode, dev); |
67 | } | |
f92ef572 | 68 | #endif |
31e12522 AT |
69 | |
70 | int do_rmdir(char *pathname) | |
71 | { | |
72 | if (dry_run) return 0; | |
f0fca04e | 73 | CHECK_RO |
31e12522 AT |
74 | return rmdir(pathname); |
75 | } | |
76 | ||
77 | int do_open(char *pathname, int flags, mode_t mode) | |
78 | { | |
3420c8e6 DD |
79 | if (flags != O_RDONLY) { |
80 | if (dry_run) return -1; | |
81 | CHECK_RO | |
82 | } | |
a926daec DD |
83 | #ifdef O_BINARY |
84 | /* for Windows */ | |
85 | flags |= O_BINARY; | |
86 | #endif | |
b0f3f578 AT |
87 | /* some systems can't handle a double / */ |
88 | if (pathname[0] == '/' && pathname[1] == '/') pathname++; | |
89 | ||
31e12522 AT |
90 | return open(pathname, flags, mode); |
91 | } | |
7308bd66 | 92 | |
f92ef572 | 93 | #if HAVE_CHMOD |
7308bd66 AT |
94 | int do_chmod(const char *path, mode_t mode) |
95 | { | |
96 | if (dry_run) return 0; | |
f0fca04e | 97 | CHECK_RO |
7308bd66 AT |
98 | return chmod(path, mode); |
99 | } | |
f92ef572 | 100 | #endif |
1b2d733a AT |
101 | |
102 | int do_rename(char *fname1, char *fname2) | |
103 | { | |
104 | if (dry_run) return 0; | |
f0fca04e | 105 | CHECK_RO |
1b2d733a AT |
106 | return rename(fname1, fname2); |
107 | } | |
108 | ||
109 | int do_mkdir(char *fname, mode_t mode) | |
110 | { | |
111 | if (dry_run) return 0; | |
f0fca04e | 112 | CHECK_RO |
1b2d733a AT |
113 | return mkdir(fname, mode); |
114 | } | |
115 | ||
116 | char *do_mktemp(char *template) | |
117 | { | |
118 | if (dry_run) return NULL; | |
f0fca04e | 119 | if (read_only) {errno = EROFS; return NULL;} |
1b2d733a AT |
120 | return mktemp(template); |
121 | } | |
bcacc18b AT |
122 | |
123 | int do_stat(const char *fname, STRUCT_STAT *st) | |
124 | { | |
125 | #if HAVE_OFF64_T | |
126 | return stat64(fname, st); | |
127 | #else | |
128 | return stat(fname, st); | |
129 | #endif | |
130 | } | |
131 | ||
efb2f6bf | 132 | #if SUPPORT_LINKS |
bcacc18b AT |
133 | int do_lstat(const char *fname, STRUCT_STAT *st) |
134 | { | |
135 | #if HAVE_OFF64_T | |
136 | return lstat64(fname, st); | |
137 | #else | |
138 | return lstat(fname, st); | |
139 | #endif | |
140 | } | |
efb2f6bf | 141 | #endif |
bcacc18b AT |
142 | |
143 | int do_fstat(int fd, STRUCT_STAT *st) | |
144 | { | |
145 | #if HAVE_OFF64_T | |
146 | return fstat64(fd, st); | |
147 | #else | |
148 | return fstat(fd, st); | |
149 | #endif | |
150 | } | |
73233f0f AT |
151 | |
152 | OFF_T do_lseek(int fd, OFF_T offset, int whence) | |
153 | { | |
154 | #if HAVE_OFF64_T | |
f28ee65b | 155 | off64_t lseek64(); |
73233f0f AT |
156 | return lseek64(fd, offset, whence); |
157 | #else | |
158 | return lseek(fd, offset, whence); | |
159 | #endif | |
160 | } | |
d6e6ecbd | 161 | |
bb0f7089 | 162 | #ifdef USE_MMAP |
754d120c AT |
163 | void *do_mmap(void *start, int len, int prot, int flags, int fd, OFF_T offset) |
164 | { | |
165 | #if HAVE_OFF64_T | |
166 | return mmap64(start, len, prot, flags, fd, offset); | |
167 | #else | |
168 | return mmap(start, len, prot, flags, fd, offset); | |
169 | #endif | |
170 | } | |
171 | #endif | |
172 | ||
d6e6ecbd AT |
173 | char *d_name(struct dirent *di) |
174 | { | |
59503278 AT |
175 | #if HAVE_BROKEN_READDIR |
176 | return (di->d_name - 2); | |
177 | #else | |
d6e6ecbd | 178 | return di->d_name; |
59503278 | 179 | #endif |
d6e6ecbd | 180 | } |