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 AT |
26 | extern int read_only; |
27 | ||
28 | #define CHECK_RO if (read_only) {errno = EROFS; return -1;} | |
31e12522 AT |
29 | |
30 | int do_unlink(char *fname) | |
31 | { | |
32 | if (dry_run) return 0; | |
f0fca04e | 33 | CHECK_RO |
31e12522 AT |
34 | return unlink(fname); |
35 | } | |
36 | ||
37 | int 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 |
45 | int 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 |
53 | int 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 |
61 | int 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 | |
69 | int do_rmdir(char *pathname) | |
70 | { | |
71 | if (dry_run) return 0; | |
f0fca04e | 72 | CHECK_RO |
31e12522 AT |
73 | return rmdir(pathname); |
74 | } | |
75 | ||
76 | int do_open(char *pathname, int flags, mode_t mode) | |
77 | { | |
78 | if (dry_run) return -1; | |
a926daec DD |
79 | #ifdef O_BINARY |
80 | /* for Windows */ | |
81 | flags |= O_BINARY; | |
82 | #endif | |
f0fca04e | 83 | CHECK_RO |
31e12522 AT |
84 | return open(pathname, flags, mode); |
85 | } | |
7308bd66 | 86 | |
f92ef572 | 87 | #if HAVE_CHMOD |
7308bd66 AT |
88 | int do_chmod(const char *path, mode_t mode) |
89 | { | |
90 | if (dry_run) return 0; | |
f0fca04e | 91 | CHECK_RO |
7308bd66 AT |
92 | return chmod(path, mode); |
93 | } | |
f92ef572 | 94 | #endif |
1b2d733a AT |
95 | |
96 | int do_rename(char *fname1, char *fname2) | |
97 | { | |
98 | if (dry_run) return 0; | |
f0fca04e | 99 | CHECK_RO |
1b2d733a AT |
100 | return rename(fname1, fname2); |
101 | } | |
102 | ||
103 | int do_mkdir(char *fname, mode_t mode) | |
104 | { | |
105 | if (dry_run) return 0; | |
f0fca04e | 106 | CHECK_RO |
1b2d733a AT |
107 | return mkdir(fname, mode); |
108 | } | |
109 | ||
110 | char *do_mktemp(char *template) | |
111 | { | |
112 | if (dry_run) return NULL; | |
f0fca04e | 113 | if (read_only) {errno = EROFS; return NULL;} |
1b2d733a AT |
114 | return mktemp(template); |
115 | } | |
bcacc18b AT |
116 | |
117 | int do_stat(const char *fname, STRUCT_STAT *st) | |
118 | { | |
119 | #if HAVE_OFF64_T | |
120 | return stat64(fname, st); | |
121 | #else | |
122 | return stat(fname, st); | |
123 | #endif | |
124 | } | |
125 | ||
efb2f6bf | 126 | #if SUPPORT_LINKS |
bcacc18b AT |
127 | int do_lstat(const char *fname, STRUCT_STAT *st) |
128 | { | |
129 | #if HAVE_OFF64_T | |
130 | return lstat64(fname, st); | |
131 | #else | |
132 | return lstat(fname, st); | |
133 | #endif | |
134 | } | |
efb2f6bf | 135 | #endif |
bcacc18b AT |
136 | |
137 | int do_fstat(int fd, STRUCT_STAT *st) | |
138 | { | |
139 | #if HAVE_OFF64_T | |
140 | return fstat64(fd, st); | |
141 | #else | |
142 | return fstat(fd, st); | |
143 | #endif | |
144 | } | |
73233f0f AT |
145 | |
146 | OFF_T do_lseek(int fd, OFF_T offset, int whence) | |
147 | { | |
148 | #if HAVE_OFF64_T | |
f28ee65b | 149 | off64_t lseek64(); |
73233f0f AT |
150 | return lseek64(fd, offset, whence); |
151 | #else | |
152 | return lseek(fd, offset, whence); | |
153 | #endif | |
154 | } | |
d6e6ecbd | 155 | |
bb0f7089 | 156 | #ifdef USE_MMAP |
754d120c AT |
157 | void *do_mmap(void *start, int len, int prot, int flags, int fd, OFF_T offset) |
158 | { | |
159 | #if HAVE_OFF64_T | |
160 | return mmap64(start, len, prot, flags, fd, offset); | |
161 | #else | |
162 | return mmap(start, len, prot, flags, fd, offset); | |
163 | #endif | |
164 | } | |
165 | #endif | |
166 | ||
d6e6ecbd AT |
167 | char *d_name(struct dirent *di) |
168 | { | |
59503278 AT |
169 | #if HAVE_BROKEN_READDIR |
170 | return (di->d_name - 2); | |
171 | #else | |
d6e6ecbd | 172 | return di->d_name; |
59503278 | 173 | #endif |
d6e6ecbd | 174 | } |