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 --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; 46#endif 47static const char rcsid[] = |
48 "$FreeBSD: head/bin/mv/mv.c 76878 2001-05-20 05:00:16Z kris $"; |
49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/time.h> 53#include <sys/wait.h> 54#include <sys/stat.h> 55#include <sys/mount.h> 56 --- 8 unchanged lines hidden (view full) --- 65 66#include "pathnames.h" 67 68int fflg, iflg, vflg; 69 70int copy __P((char *, char *)); 71int do_move __P((char *, char *)); 72int fastcopy __P((char *, char *, struct stat *)); |
73int main __P((int, char *[])); |
74void usage __P((void)); 75 76int 77main(argc, argv) 78 int argc; 79 char *argv[]; 80{ 81 register int baselen, len, rval; --- 54 unchanged lines hidden (view full) --- 136 --p; 137 while (p != *argv && p[-1] != '/') 138 --p; 139 140 if ((baselen + (len = strlen(p))) >= MAXPATHLEN) { 141 warnx("%s: destination pathname too long", *argv); 142 rval = 1; 143 } else { |
144 memmove(endp, p, (size_t)len + 1); |
145 if (do_move(*argv, path)) 146 rval = 1; 147 } 148 } 149 exit(rval); 150} 151 152int --- 21 unchanged lines hidden (view full) --- 174 ask = 0; 175 if (iflg) { 176 (void)fprintf(stderr, "overwrite %s? %s", to, YESNO); 177 ask = 1; 178 } else if (access(to, W_OK) && !stat(to, &sb)) { 179 strmode(sb.st_mode, modep); 180 (void)fprintf(stderr, "override %s%s%s/%s for %s? %s", 181 modep + 1, modep[9] == ' ' ? "" : " ", |
182 user_from_uid((unsigned long)sb.st_uid, 0), 183 group_from_gid((unsigned long)sb.st_gid, 0), to, YESNO); |
184 ask = 1; 185 } 186 if (ask) { 187 first = ch = getchar(); 188 while (ch != '\n' && ch != EOF) 189 ch = getchar(); 190 if (first != 'y' && first != 'Y') { 191 (void)fprintf(stderr, "not overwritten\n"); --- 51 unchanged lines hidden (view full) --- 243 244 if ((from_fd = open(from, O_RDONLY, 0)) < 0) { 245 warn("%s", from); 246 return (1); 247 } 248 if (blen < sbp->st_blksize) { 249 if (bp != NULL) 250 free(bp); |
251 if ((bp = malloc((size_t)sbp->st_blksize)) == NULL) { |
252 blen = 0; 253 warnx("malloc failed"); 254 return (1); 255 } 256 blen = sbp->st_blksize; 257 } 258 while ((to_fd = 259 open(to, O_CREAT | O_EXCL | O_TRUNC | O_WRONLY, 0)) < 0) { 260 if (errno == EEXIST && unlink(to) == 0) 261 continue; 262 warn("%s", to); 263 (void)close(from_fd); 264 return (1); 265 } |
266 while ((nread = read(from_fd, bp, (size_t)blen)) > 0) 267 if (write(to_fd, bp, (size_t)nread) != nread) { |
268 warn("%s", to); 269 goto err; 270 } 271 if (nread < 0) { 272 warn("%s", from); 273err: if (unlink(to)) 274 warn("%s: remove", to); 275 (void)close(from_fd); --- 18 unchanged lines hidden (view full) --- 294 /* 295 * XXX 296 * NFS doesn't support chflags; ignore errors unless there's reason 297 * to believe we're losing bits. (Note, this still won't be right 298 * if the server supports flags and we were trying to *remove* flags 299 * on a file that we copied, i.e., that we didn't create.) 300 */ 301 errno = 0; |
302 if (fchflags(to_fd, (u_long)sbp->st_flags)) |
303 if (errno != EOPNOTSUPP || sbp->st_flags != 0) 304 warn("%s: set flags (was: 0%07o)", to, sbp->st_flags); 305 306 tval[0].tv_sec = sbp->st_atime; 307 tval[1].tv_sec = sbp->st_mtime; 308 tval[0].tv_usec = tval[1].tv_usec = 0; 309 if (utimes(to, tval)) 310 warn("%s: set times", to); --- 69 unchanged lines hidden --- |