Deleted Added
full compact
mv.c (14156) mv.c (14166)
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 *
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: mv.c,v 1.5 1996/02/19 00:44:19 wosch Exp $
36 * $Id: mv.c,v 1.6 1996/02/19 05:51:13 pst Exp $
37 */
38
39#ifndef lint
40static char 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

--- 33 unchanged lines hidden (view full) ---

78 struct stat sb;
79 int ch;
80 char path[MAXPATHLEN + 1];
81
82 while ((ch = getopt(argc, argv, "if")) != EOF)
83 switch (ch) {
84 case 'i':
85 iflg = 1;
37 */
38
39#ifndef lint
40static char 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

--- 33 unchanged lines hidden (view full) ---

78 struct stat sb;
79 int ch;
80 char path[MAXPATHLEN + 1];
81
82 while ((ch = getopt(argc, argv, "if")) != EOF)
83 switch (ch) {
84 case 'i':
85 iflg = 1;
86 fflg = 0;
86 break;
87 case 'f':
88 fflg = 1;
87 break;
88 case 'f':
89 fflg = 1;
90 iflg = 0;
89 break;
90 default:
91 usage();
92 }
93endarg: argc -= optind;
94 argv += optind;
95
96 if (argc < 2)

--- 47 unchanged lines hidden (view full) ---

144 char modep[15];
145
146 /*
147 * Check access. If interactive and file exists, ask user if it
148 * should be replaced. Otherwise if file exists but isn't writable
149 * make sure the user wants to clobber it.
150 */
151 if (!fflg && !access(to, F_OK)) {
91 break;
92 default:
93 usage();
94 }
95endarg: argc -= optind;
96 argv += optind;
97
98 if (argc < 2)

--- 47 unchanged lines hidden (view full) ---

146 char modep[15];
147
148 /*
149 * Check access. If interactive and file exists, ask user if it
150 * should be replaced. Otherwise if file exists but isn't writable
151 * make sure the user wants to clobber it.
152 */
153 if (!fflg && !access(to, F_OK)) {
154
155 /* prompt only if source exist */
156 if (lstat(from, &sb) == -1) {
157 warn("%s", from);
158 return (1);
159 }
160
152 ask = 0;
153 if (iflg) {
154 (void)fprintf(stderr, "overwrite %s? ", to);
155 ask = 1;
156 } else if (access(to, W_OK) && !stat(to, &sb)) {
157 strmode(sb.st_mode, modep);
158 (void)fprintf(stderr, "override %s%s%s/%s for %s? ",
159 modep + 1, modep[9] == ' ' ? "" : " ",
160 user_from_uid(sb.st_uid, 0),
161 group_from_gid(sb.st_gid, 0), to);
162 ask = 1;
163 }
164 if (ask) {
165 if ((ch = getchar()) != EOF && ch != '\n')
166 while (getchar() != '\n');
161 ask = 0;
162 if (iflg) {
163 (void)fprintf(stderr, "overwrite %s? ", to);
164 ask = 1;
165 } else if (access(to, W_OK) && !stat(to, &sb)) {
166 strmode(sb.st_mode, modep);
167 (void)fprintf(stderr, "override %s%s%s/%s for %s? ",
168 modep + 1, modep[9] == ' ' ? "" : " ",
169 user_from_uid(sb.st_uid, 0),
170 group_from_gid(sb.st_gid, 0), to);
171 ask = 1;
172 }
173 if (ask) {
174 if ((ch = getchar()) != EOF && ch != '\n')
175 while (getchar() != '\n');
167 if (ch != 'y')
176 if (ch != 'y' && ch != 'Y')
168 return (0);
169 }
170 }
171 if (!rename(from, to))
172 return (0);
173
174 if (errno != EXDEV) {
175 warn("rename %s to %s", from, to);

--- 118 unchanged lines hidden (view full) ---

294 return (1);
295 }
296 return (0);
297}
298
299void
300usage()
301{
177 return (0);
178 }
179 }
180 if (!rename(from, to))
181 return (0);
182
183 if (errno != EXDEV) {
184 warn("rename %s to %s", from, to);

--- 118 unchanged lines hidden (view full) ---

303 return (1);
304 }
305 return (0);
306}
307
308void
309usage()
310{
302 (void)fprintf(stderr,
303"usage: mv [-if] src target;\n or: mv [-if] src1 ... srcN directory\n");
311 (void)fprintf(stderr,
312"\
313usage: mv [-i | -f] src target;\n\
314 or: mv [-i | -f] src1 ... srcN directory\n");
304 exit(1);
305}
315 exit(1);
316}