]>
git.ipfire.org Git - thirdparty/rsync.git/blob - syscall.c
2 Copyright (C) Andrew Tridgell 1998
3 Copyright (C) 2002 by Martin Pool
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.
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.
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.
23 * Syscall wrappers to ensure that nothing gets done in dry_run mode
24 * and to handle system peculiarities.
32 extern int preserve_perms
;
34 #define RETURN_ERROR_IF(x,e) \
42 #define RETURN_ERROR_IF_RO_OR_LO RETURN_ERROR_IF(read_only || list_only, EROFS)
44 int do_unlink(char *fname
)
46 if (dry_run
) return 0;
47 RETURN_ERROR_IF_RO_OR_LO
;
51 int do_symlink(char *fname1
, char *fname2
)
53 if (dry_run
) return 0;
54 RETURN_ERROR_IF_RO_OR_LO
;
55 return symlink(fname1
, fname2
);
59 int do_link(char *fname1
, char *fname2
)
61 if (dry_run
) return 0;
62 RETURN_ERROR_IF_RO_OR_LO
;
63 return link(fname1
, fname2
);
67 int do_lchown(const char *path
, uid_t owner
, gid_t group
)
69 if (dry_run
) return 0;
70 RETURN_ERROR_IF_RO_OR_LO
;
71 return lchown(path
, owner
, group
);
75 int do_mknod(char *pathname
, mode_t mode
, dev_t dev
)
77 if (dry_run
) return 0;
78 RETURN_ERROR_IF_RO_OR_LO
;
79 return mknod(pathname
, mode
, dev
);
83 int do_rmdir(char *pathname
)
85 if (dry_run
) return 0;
86 RETURN_ERROR_IF_RO_OR_LO
;
87 return rmdir(pathname
);
90 int do_open(char *pathname
, int flags
, mode_t mode
)
92 if (flags
!= O_RDONLY
) {
93 RETURN_ERROR_IF(dry_run
, 0);
94 RETURN_ERROR_IF_RO_OR_LO
;
97 return open(pathname
, flags
| O_BINARY
, mode
);
101 int do_chmod(const char *path
, mode_t mode
)
104 if (dry_run
) return 0;
105 RETURN_ERROR_IF_RO_OR_LO
;
106 code
= chmod(path
, mode
);
107 if (code
!= 0 && preserve_perms
)
113 int do_rename(char *fname1
, char *fname2
)
115 if (dry_run
) return 0;
116 RETURN_ERROR_IF_RO_OR_LO
;
117 return rename(fname1
, fname2
);
121 void trim_trailing_slashes(char *name
)
124 /* Some BSD systems cannot make a directory if the name
125 * contains a trailing slash.
126 * <http://www.opensource.apple.com/bugs/X/BSD%20Kernel/2734739.html> */
128 /* Don't change empty string; and also we can't improve on
133 if (name
[--l
] != '/')
140 int do_mkdir(char *fname
, mode_t mode
)
142 if (dry_run
) return 0;
143 RETURN_ERROR_IF_RO_OR_LO
;
144 trim_trailing_slashes(fname
);
145 return mkdir(fname
, mode
);
149 /* like mkstemp but forces permissions */
150 int do_mkstemp(char *template, mode_t perms
)
152 RETURN_ERROR_IF(dry_run
, 0);
153 RETURN_ERROR_IF(read_only
, EROFS
);
155 #if defined(HAVE_SECURE_MKSTEMP) && defined(HAVE_FCHMOD)
157 int fd
= mkstemp(template);
160 if (fchmod(fd
, perms
) != 0 && preserve_perms
) {
161 int errno_save
= errno
;
170 if (!mktemp(template))
172 return do_open(template, O_RDWR
|O_EXCL
|O_CREAT
, perms
);
176 int do_stat(const char *fname
, STRUCT_STAT
*st
)
179 return stat64(fname
, st
);
181 return stat(fname
, st
);
186 int do_lstat(const char *fname
, STRUCT_STAT
*st
)
189 return lstat64(fname
, st
);
191 return lstat(fname
, st
);
196 int do_fstat(int fd
, STRUCT_STAT
*st
)
199 return fstat64(fd
, st
);
201 return fstat(fd
, st
);
205 OFF_T
do_lseek(int fd
, OFF_T offset
, int whence
)
209 return lseek64(fd
, offset
, whence
);
211 return lseek(fd
, offset
, whence
);
216 void *do_mmap(void *start
, int len
, int prot
, int flags
, int fd
, OFF_T offset
)
219 return mmap64(start
, len
, prot
, flags
, fd
, offset
);
221 return mmap(start
, len
, prot
, flags
, fd
, offset
);
226 char *d_name(struct dirent
*di
)
228 #if HAVE_BROKEN_READDIR
229 return (di
->d_name
- 2);