* Copyright (c) 1987 Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1987 Regents of the University of California.\n\
static char sccsid
[] = "@(#)ln.c 5.1 (Berkeley) %G%";
int dirflag
, /* Undocumented force flag. */
sflag
, /* Symbolic, not hard, link. */
(*linkf
) __P((const char *, const char *));
static int linkit
__P((char *, char *, int));
static void usage
__P((void));
while ((ch
= getopt(argc
, argv
, "Fs")) != EOF
)
linkf
= sflag
? symlink
: link
;
exit(linkit(argv
[0], ".", 1));
case 2: /* ln target source */
exit(linkit(argv
[0], argv
[1], 0));
/* ln target1 target2 directory */
sourcedir
= argv
[argc
- 1];
if (stat(sourcedir
, &sb
))
if (!S_ISDIR(sb
.st_mode
))
for (exitval
= 0; *argv
!= sourcedir
; ++argv
)
exitval
|= linkit(*argv
, sourcedir
, 1);
linkit(target
, source
, isdir
)
char path
[MAXPATHLEN
], *p
;
/* if target doesn't exist, quit now */
/* only symbolic links to directories, unless -F option used */
if (!dirflag
&& (sb
.st_mode
& S_IFMT
) == S_IFDIR
) {
warnx("%s: is a directory", target
);
/* if the source is a directory, append the target's name */
if (isdir
|| !stat(source
, &sb
) && (sb
.st_mode
& S_IFMT
) == S_IFDIR
) {
if (!(p
= strrchr(target
, '/')))
(void)snprintf(path
, sizeof(path
), "%s/%s", source
, p
);
if ((*linkf
)(target
, source
)) {
"usage:\tln [-s] file1 file2\n\tln [-s] file ... directory\n");