projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
new vm
[unix-history]
/
usr
/
src
/
bin
/
ln
/
ln.c
diff --git
a/usr/src/bin/ln/ln.c
b/usr/src/bin/ln/ln.c
index
225d27b
..
038599f
100644
(file)
--- a/
usr/src/bin/ln/ln.c
+++ b/
usr/src/bin/ln/ln.c
@@
-12,21
+12,25
@@
char copyright[] =
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)ln.c 4.1
3
(Berkeley) %G%";
+static char sccsid[] = "@(#)ln.c 4.1
5
(Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
static int dirflag, /* undocumented force flag */
sflag, /* symbolic, not hard, link */
(*linkf)(); /* system link call */
static int dirflag, /* undocumented force flag */
sflag, /* symbolic, not hard, link */
(*linkf)(); /* system link call */
+static linkit(), usage();
main(argc, argv)
main(argc, argv)
- int
argc;
- char
**argv;
+ int argc;
+ char **argv;
{
extern int optind;
struct stat buf;
{
extern int optind;
struct stat buf;
@@
-61,37
+65,37
@@
main(argc, argv)
default: /* ln target1 target2 directory */
sourcedir = argv[argc - 1];
if (stat(sourcedir, &buf)) {
default: /* ln target1 target2 directory */
sourcedir = argv[argc - 1];
if (stat(sourcedir, &buf)) {
- perror(sourcedir);
+ (void)fprintf(stderr,
+ "ln: %s: %s\n", sourcedir, strerror(errno));
exit(1);
}
exit(1);
}
- if (
(buf.st_mode & S_IFMT) != S_IFDIR
)
+ if (
!S_ISDIR(buf.st_mode)
)
usage();
for (exitval = 0; *argv != sourcedir; ++argv)
exitval |= linkit(*argv, sourcedir, 1);
exit(exitval);
}
usage();
for (exitval = 0; *argv != sourcedir; ++argv)
exitval |= linkit(*argv, sourcedir, 1);
exit(exitval);
}
- /*
NOTREACHED
*/
+ /*
NOTREACHED
*/
}
static
linkit(target, source, isdir)
}
static
linkit(target, source, isdir)
- char
*target, *source;
- int
isdir;
+ char *target, *source;
+ int isdir;
{
{
- extern int errno;
- struct stat buf;
- char path[MAXPATHLEN],
- *cp, *rindex(), *strcpy();
+ struct stat buf;
+ char path[MAXPATHLEN], *cp;
if (!sflag) {
/* if target doesn't exist, quit now */
if (stat(target, &buf)) {
if (!sflag) {
/* if target doesn't exist, quit now */
if (stat(target, &buf)) {
- perror(target);
+ (void)fprintf(stderr,
+ "ln: %s: %s\n", target, strerror(errno));
return(1);
}
/* only symbolic links to directories, unless -F option used */
if (!dirflag && (buf.st_mode & S_IFMT) == S_IFDIR) {
return(1);
}
/* only symbolic links to directories, unless -F option used */
if (!dirflag && (buf.st_mode & S_IFMT) == S_IFDIR) {
-
printf("
%s is a directory.\n", target);
+
(void)printf("ln:
%s is a directory.\n", target);
return(1);
}
}
return(1);
}
}
@@
-107,7
+111,7
@@
linkit(target, source, isdir)
}
if ((*linkf)(target, source)) {
}
if ((*linkf)(target, source)) {
-
perror(source
);
+
(void)fprintf(stderr, "ln: %s: %s\n", source, strerror(errno)
);
return(1);
}
return(0);
return(1);
}
return(0);
@@
-116,6
+120,7
@@
linkit(target, source, isdir)
static
usage()
{
static
usage()
{
- fputs("usage:\tln [-s] targetname [sourcename]\n\tln [-s] targetname1 targetname2 [... targetnameN] sourcedirectory\n", stderr);
+ (void)fprintf(stderr,
+ "usage:\tln [-s] file1 file2\n\tln [-s] file ... directory\n");
exit(1);
}
exit(1);
}