diff options
author | sheldonh <sheldonh@FreeBSD.org> | 2000-08-17 16:08:06 +0000 |
---|---|---|
committer | sheldonh <sheldonh@FreeBSD.org> | 2000-08-17 16:08:06 +0000 |
commit | 1c5470e606da102af54b9d6fb48a41a645c33026 (patch) | |
tree | a63f012c13631f80a56cbc40909d1f7258c490f1 /bin/ln | |
parent | 8ec855315e8a2fb8fd60c8052fc1f36ecdceacc9 (diff) | |
download | FreeBSD-src-1c5470e606da102af54b9d6fb48a41a645c33026.zip FreeBSD-src-1c5470e606da102af54b9d6fb48a41a645c33026.tar.gz |
Fix style bugs and inconsistencies introduced in rev 1.16.
Submitted by: bde
Diffstat (limited to 'bin/ln')
-rw-r--r-- | bin/ln/ln.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/bin/ln/ln.c b/bin/ln/ln.c index 686e031..27c6a82 100644 --- a/bin/ln/ln.c +++ b/bin/ln/ln.c @@ -92,17 +92,15 @@ main(argc, argv) usage(); } - fflag = iflag = sflag = vflag = 0; - while ((ch = getopt(argc, argv, "fisv")) != -1) switch (ch) { case 'f': fflag = 1; - iflag = 0; /* -f overrides iflag */ + iflag = 0; break; case 'i': iflag = 1; - fflag = 0; /* -i overrides fflag */ + fflag = 0; break; case 's': sflag = 1; @@ -146,7 +144,7 @@ linkit(target, source, isdir) int isdir; { struct stat sb; - int exists, ch, first; + int ch, exists, first; char *p, path[MAXPATHLEN]; if (!sflag) { @@ -176,25 +174,33 @@ linkit(target, source, isdir) exists = !lstat(source, &sb); /* - * If the file exists, and -f was specified, unlink it. - * Attempt the link. + * If the file exists, then unlink it forcibly if -f was specified + * and interactively if -i was specified. */ - if (fflag && exists && unlink(source)) { - warn("%s", source); - return (1); + if (fflag && exists) { + if (unlink(source)) { + warn("%s", source); + return (1); + } } else if (iflag && exists) { + fflush(stdout); fprintf(stderr, "replace %s? ", source); - fflush(stderr); first = ch = getchar(); while(ch != '\n' && ch != EOF) ch = getchar(); + if (first != 'y' && first != 'Y') { + fprintf(stderr, "not replaced\n"); + return (1); + } - if ((first == 'y' || first == 'Y') && unlink(source)) { + if (unlink(source)) { warn("%s", source); return (1); } } + + /* Attempt the link. */ if ((*linkf)(target, source)) { warn("%s", source); return (1); |