summaryrefslogtreecommitdiffstats
path: root/bin/mv/mv.c
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1996-02-18 18:44:58 +0000
committerwosch <wosch@FreeBSD.org>1996-02-18 18:44:58 +0000
commitca465af3df8c4e6f751237d66fc017487093bb12 (patch)
treeec0d9a20b1d60ba2839257a98673256b0eb3673d /bin/mv/mv.c
parentad8b686ee4868d4d62e9deb5c9d8b799888cc8dc (diff)
downloadFreeBSD-src-ca465af3df8c4e6f751237d66fc017487093bb12.zip
FreeBSD-src-ca465af3df8c4e6f751237d66fc017487093bb12.tar.gz
option -f and -i are exclusive
all flag variables initialized with zero respond `Y' is equal to `y' update usage string prompt only if source exist ignore -i option if file descriptor stdin not refers to a valid terminal type device
Diffstat (limited to 'bin/mv/mv.c')
-rw-r--r--bin/mv/mv.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index 91217d3..0a3d35e 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: mv.c,v 1.2 1994/09/24 02:56:07 davidg Exp $
+ * $Id: mv.c,v 1.3 1995/10/07 10:42:48 bde Exp $
*/
#ifndef lint
@@ -79,13 +79,17 @@ main(argc, argv)
int ch;
char path[MAXPATHLEN + 1];
- while ((ch = getopt(argc, argv, "-if")) != EOF)
+ fflg = iflg = 0;
+
+ while ((ch = getopt(argc, argv, "-if?")) != EOF)
switch (ch) {
case 'i':
- iflg = 1;
+ iflg = isatty(STDIN_FILENO);
+ fflg = 0;
break;
case 'f':
fflg = 1;
+ iflg = 0;
break;
case '-': /* Undocumented; for compatibility. */
goto endarg;
@@ -152,6 +156,13 @@ do_move(from, to)
* make sure the user wants to clobber it.
*/
if (!fflg && !access(to, F_OK)) {
+
+ /* prompt only if source exist */
+ if (lstat(from, &sb) == -1) {
+ warn("%s", from);
+ return (1);
+ }
+
ask = 0;
if (iflg) {
(void)fprintf(stderr, "overwrite %s? ", to);
@@ -167,7 +178,7 @@ do_move(from, to)
if (ask) {
if ((ch = getchar()) != EOF && ch != '\n')
while (getchar() != '\n');
- if (ch != 'y')
+ if (ch != 'y' && ch != 'Y')
return (0);
}
}
@@ -303,6 +314,6 @@ void
usage()
{
(void)fprintf(stderr,
-"usage: mv [-if] src target;\n or: mv [-if] src1 ... srcN directory\n");
+"usage: mv [-if] src target;\n or: mv [-i | -f] src1 ... srcN directory\n");
exit(1);
}
OpenPOWER on IntegriCloud