aboutsummaryrefslogtreecommitdiff
path: root/bin/ln
diff options
context:
space:
mode:
authorSheldon Hearn <sheldonh@FreeBSD.org>2000-08-17 16:08:06 +0000
committerSheldon Hearn <sheldonh@FreeBSD.org>2000-08-17 16:08:06 +0000
commit7e7574af897c2cda6391d6b596807aaf2dc25d19 (patch)
treedafd1f05a2e99c602e82e5f439da73ec3837e63e /bin/ln
parentae361066618fb3017e28a146271e5da2c1b4dbdc (diff)
downloadsrc-7e7574af897c2cda6391d6b596807aaf2dc25d19.tar.gz
src-7e7574af897c2cda6391d6b596807aaf2dc25d19.zip
Fix style bugs and inconsistencies introduced in rev 1.16.
Submitted by: bde
Notes
Notes: svn path=/head/; revision=64787
Diffstat (limited to 'bin/ln')
-rw-r--r--bin/ln/ln.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/bin/ln/ln.c b/bin/ln/ln.c
index 686e031e50ce..27c6a82a8c5a 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);