1/*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ken Smith of The State University of New York at Buffalo.
7 *
8 * Redistribution and use in source and binary forms, with or without
--- 19 unchanged lines hidden (view full) ---
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id$
37 */
38
39#ifndef lint
40static char const copyright[] =
41"@(#) Copyright (c) 1989, 1993, 1994\n\
42 The Regents of the University of California. All rights reserved.\n";
43#endif /* not lint */
44
--- 156 unchanged lines hidden (view full) ---
201int
202fastcopy(from, to, sbp)
203 char *from, *to;
204 struct stat *sbp;
205{
206 struct timeval tval[2];
207 static u_int blen;
208 static char *bp;
209 register int nread, from_fd, to_fd;
210
211 if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
212 warn("%s", from);
213 return (1);
214 }
215 if ((to_fd =
216 open(to, O_CREAT | O_TRUNC | O_WRONLY, sbp->st_mode)) < 0) {
217 warn("%s", to);
218 (void)close(from_fd);
219 return (1);
220 }
221 if (!blen && !(bp = malloc(blen = sbp->st_blksize))) {
222 warn(NULL);
223 return (1);
224 }
225 while ((nread = read(from_fd, bp, blen)) > 0)
226 if (write(to_fd, bp, nread) != nread) {
227 warn("%s", to);
228 goto err;
229 }
230 if (nread < 0) {
231 warn("%s", from);
232err: if (unlink(to))
233 warn("%s: remove", to);
234 (void)close(from_fd);
235 (void)close(to_fd);
236 return (1);
237 }
238 (void)close(from_fd);
239
240 if (fchown(to_fd, sbp->st_uid, sbp->st_gid))
241 warn("%s: set owner/group", to);
242 if (fchmod(to_fd, sbp->st_mode))
243 warn("%s: set mode", to);
244
245 tval[0].tv_sec = sbp->st_atime;
246 tval[1].tv_sec = sbp->st_mtime;
247 tval[0].tv_usec = tval[1].tv_usec = 0;
248 if (utimes(to, tval))
249 warn("%s: set times", to);
250
251 if (close(to_fd)) {
--- 64 unchanged lines hidden ---
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ken Smith of The State University of New York at Buffalo.
7 *
8 * Redistribution and use in source and binary forms, with or without
--- 19 unchanged lines hidden (view full) ---
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id$
37 */
38
39#ifndef lint
40static char const copyright[] =
41"@(#) Copyright (c) 1989, 1993, 1994\n\
42 The Regents of the University of California. All rights reserved.\n";
43#endif /* not lint */
44
--- 156 unchanged lines hidden (view full) ---
201int
202fastcopy(from, to, sbp)
203 char *from, *to;
204 struct stat *sbp;
205{
206 struct timeval tval[2];
207 static u_int blen;
208 static char *bp;
209 register int nread, from_fd, to_fd;
210
211 if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
212 warn("%s", from);
213 return (1);
214 }
215 if ((to_fd =
216 open(to, O_CREAT | O_TRUNC | O_WRONLY, sbp->st_mode)) < 0) {
217 warn("%s", to);
218 (void)close(from_fd);
219 return (1);
220 }
221 if (!blen && !(bp = malloc(blen = sbp->st_blksize))) {
222 warn(NULL);
223 return (1);
224 }
225 while ((nread = read(from_fd, bp, blen)) > 0)
226 if (write(to_fd, bp, nread) != nread) {
227 warn("%s", to);
228 goto err;
229 }
230 if (nread < 0) {
231 warn("%s", from);
232err: if (unlink(to))
233 warn("%s: remove", to);
234 (void)close(from_fd);
235 (void)close(to_fd);
236 return (1);
237 }
238 (void)close(from_fd);
239
240 if (fchown(to_fd, sbp->st_uid, sbp->st_gid))
241 warn("%s: set owner/group", to);
242 if (fchmod(to_fd, sbp->st_mode))
243 warn("%s: set mode", to);
244
245 tval[0].tv_sec = sbp->st_atime;
246 tval[1].tv_sec = sbp->st_mtime;
247 tval[0].tv_usec = tval[1].tv_usec = 0;
248 if (utimes(to, tval))
249 warn("%s: set times", to);
250
251 if (close(to_fd)) {
--- 64 unchanged lines hidden ---