History log of /freebsd-current/bin/ln/ln.c
Revision Date Author Comments
# bee7cf9e 04-Apr-2024 Dag-Erling Smørgrav <des@FreeBSD.org>

ln: Improve link(1) variant of ln(1).

* Give link(1) its own usage message.
* Use getprogname(3) instead of rolling our own.
* Verify that the target file does not already exist.
* Add tests specific to link(1).

MFC after: 3 days
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D44635


# 437d53da 27-Mar-2024 Dag-Erling Smørgrav <des@FreeBSD.org>

ln: Use stdbool, style nits.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: imp, allanjude
Differential Revision: https://reviews.freebsd.org/D44511


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 90aea514 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 63bd650f 20-Jun-2017 Enji Cooper <ngie@FreeBSD.org>

ln(1): fix -F behavior

When '-F' option is used, the target directory needs to be unlinked.
Currently, the modified target ("target/source") is being unlinked, and
since it doesn't yet exist, the original target isn't removed.
This is fixed by skipping the block where target is modified to
"target/source" when '-F' option is set.
Hence, a symbolic link (with the same name as of the original target) to
the source_file is produced.

Update the test for ln(1) to reflect fix for option '-F'

MFC after: 1 month
PR: 219943
Differential Revision: D11167
Submitted by: shivansh
Sponsored by: Google (GSoC 2017)


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 08aa7c86 02-Jun-2013 Eitan Adler <eadler@FreeBSD.org>

Add 'static' where able.


# f9d4afb4 31-Oct-2011 Ed Schouten <ed@FreeBSD.org>

Put some static keywords in the source code.

For these simple utilities, it doesn't harm to make all global variables
static. In fact, this allows the compiler to perform better forms of
optimisation and analysis.


# 0cf90cd1 15-Mar-2011 Jilles Tjoelker <jilles@FreeBSD.org>

bin: Prefer strrchr() to rindex().

This removes the last index/rindex usage from /bin.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 312a3c0c 01-May-2010 Jilles Tjoelker <jilles@FreeBSD.org>

MFC r207021: ln: Allow a trailing slash when creating a link to a directory.

In the 'ln source... directory' synopsis, the basename of each source
determines the name of the created link. Determine this using basename(3)
instead of strrchr(..., '/') which is incorrect if the pathname ends in a
slash.

PR: 121568


# 1577aa79 01-May-2010 Jilles Tjoelker <jilles@FreeBSD.org>

MFC r206773: ln: Do not delete a file by hardlinking it to itself.

Two pathnames refer to the same directory entry iff the directories match
and the final components' names match.

Example: (assuming file1 is an existing file)
ln -f file1 file1
This now fails while leaving file1 intact. It used to delete file1 and then
complain it cannot be linked because it is gone.

With -i, this error is detected before the question is asked.


# dc00aa5d 21-Apr-2010 Jilles Tjoelker <jilles@FreeBSD.org>

ln: Allow a trailing slash when creating a link to a directory.

In the 'ln source... directory' synopsis, the basename of each source
determines the name of the created link. Determine this using basename(3)
instead of strrchr(..., '/') which is incorrect if the pathname ends in a
slash.

The patch is somewhat changed to allow for basename(3) implementations that
change the passed pathname, and to fix the -w option's checking also.
The code to compare directory entries only applies to hard links, which
cannot be created to directories using ln.

Example:
ln -s /etc/defaults/ /tmp
This should create a symlink named defaults.

PR: 121568
Submitted by: Ighighi
MFC after: 1 week


# 5d66b54e 17-Apr-2010 Jilles Tjoelker <jilles@FreeBSD.org>

ln: Refuse deleting a directory entry by hardlinking it to itself.

Two pathnames refer to the same directory entry iff the directories match
and the final components' names match.

Example: (assuming file1 is an existing file)
ln -f file1 file1
This now fails while leaving file1 intact. It used to delete file1 and then
complain it cannot be linked because it is gone.

With -i, this error is detected before the question is asked.

MFC after: 2 weeks


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 80a0e9b5 19-Jul-2009 Jilles Tjoelker <jilles@FreeBSD.org>

Allow creating hard links to symlinks using ln(1).

This implements the POSIX.1-2008 -L and -P flags.

The default remains to create hard links to the target of symlinks.

Approved by: re (kib), ed (mentor)


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# d605a06c 07-Jun-2008 Giorgos Keramidas <keramida@FreeBSD.org>

Unbreak last commit to ln for amd64.

Cast string precision to `int'. amd64 systems warn about the
field precision being `long int' if we don't, and pathnames are
normally short enough to fit in an `int'.

Noticed by: pav


# 3595f21a 06-Jun-2008 Giorgos Keramidas <keramida@FreeBSD.org>

Add a -w warning flag to ln(1). When the -w option is enabled,
ln(1) checks to see if the source of a symlink, i.e. the file it
should point to actually exists. The default is the old ln
behavior, that does not check, to avoid surprising people who may
be using ln(1) in scripts or other non-interactive places.

PR: bin/7265
Submitted by: Joel Ray Holveck, detlev!joelh at mail.camalott.com
MFC after: 2 weeks


# 80906944 17-Nov-2007 Ruslan Ermilov <ru@FreeBSD.org>

Express in the usage() and SYNOPSIS that -F depends on -s, and
that -f and -i are exclusive.


# cadf8ad7 17-Nov-2007 Ruslan Ermilov <ru@FreeBSD.org>

Swap "source"/"target" where appropriate, to match documentation.


# 5e09de40 14-Feb-2006 Gleb Smirnoff <glebius@FreeBSD.org>

Add '-F' option which allows to delete existing empty directories, when
creating symbolic links.

PR: bin/92149
Submitted by: Eugene Grosbein <eugen grosbein.pp.ru>


# a89237ae 09-Feb-2005 Ruslan Ermilov <ru@FreeBSD.org>

Sync program's usage() with manpage's SYNOPSIS.


# 9ddb49cb 10-Jan-2005 Warner Losh <imp@FreeBSD.org>

/*- or .\"- or #- to begin license clauses.


# 6195fb41 06-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 09a80d48 01-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Quiet warnings about copyright[].


# f193e3fc 31-Jul-2002 Mark Murray <markm@FreeBSD.org>

Fix an easy WARNS.


# 5eb43ac2 29-Jun-2002 David E. O'Brien <obrien@FreeBSD.org>

Consistently use __FBSDID


# a24ce1c8 28-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Check that snprintf() does not truncate the destination pathname when
linking into a directory.


# dab94652 29-May-2002 Tim J. Robbins <tjr@FreeBSD.org>

Reject options, handle "--" end-of-options marker in link(1).


# 75a01126 10-May-2002 Chris D. Faulhaber <jedgar@FreeBSD.org>

Add semicolon to empty default case to silence warning.


# 4b4ed2fe 22-Feb-2002 Mark Murray <markm@FreeBSD.org>

Fix warnings inspired by lint, a commercial lint and WARNS=4.


# 46251dde 01-Feb-2002 Warner Losh <imp@FreeBSD.org>

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.


# c215688f 29-May-2001 Warner Losh <imp@FreeBSD.org>

Use PATH_MAX in preference to MAXPATHLEN.

Also sort declarations per style(9) (big arrays come last) while I'm
in the area.


# 97dbc8f3 19-May-2001 Kris Kennaway <kris@FreeBSD.org>

Silence WARNS=2 and BDECFLAGS on i386 and alpha

MFC After: 1 week


# c9e7c667 26-Apr-2001 Maxim Sobolev <sobomax@FreeBSD.org>

Bring in `-h' compatability option and its alias `-n' to match NetBSD and GNU
semantics.

style(9) Reviewed by:
Obtained from: NetBSD


# 7e7574af 17-Aug-2000 Sheldon Hearn <sheldonh@FreeBSD.org>

Fix style bugs and inconsistencies introduced in rev 1.16.

Submitted by: bde


# 2c15efcf 15-Aug-2000 Warner Losh <imp@FreeBSD.org>

Don't explicitly declare optarg and optind. These are declared in
unistd.h, which is already included.


# 7fcd5ae0 14-Aug-2000 Sheldon Hearn <sheldonh@FreeBSD.org>

Add the -i option, as found in rm(1), which provides an interactive
mode in which the user is prompted for confirmation before an
existing file is replaced.

Submitted by: alex


# d71e172a 20-Dec-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Add link(1) and unlink(1) as special cases of ln(1) and rm(1)
respectively, in accordance with SUSv2.

This differs from the approach taken in NetBSD, but provides
less obscure error messages in at least the EISDIR case and
does not take up additional disk space for new binaries.

PR: 13071
PR: 13074
Requested by: James Howard <howardjp@wam.umd.edu>


# b598b073 11-Sep-1999 David E. O'Brien <obrien@FreeBSD.org>

Add verbose processing flag.


# 2a456239 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 2a170595 15-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Correct use of .Nm. Add rcsid.


# 749d4bb6 06-Jun-1997 Philippe Charnier <charnier@FreeBSD.org>

Cosmetic change in usage string.


# 93ef08af 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# b97fa2ef 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 78b09ffe 13-Dec-1996 Steve Price <steve@FreeBSD.org>

-Wall cleaning.


# 7d4b6187 24-May-1996 Peter Wemm <peter@FreeBSD.org>

Nuke the undocumented -F flag, since it doesn't do anything anymore.

It used to allow root to hard-link directories (and screw up programs that
expexted the ".." entry to point to the parent dir)


# 9195f409 06-Dec-1994 Bruce Evans <bde@FreeBSD.org>

Use lstat() instead of stat() for checking if the final source file exists,
so that `ln -fs' works when the source is a symlink pointing to a non-
existent file.


# 89730b29 23-Sep-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# c4278e8b 20-Sep-1994 Poul-Henning Kamp <phk@FreeBSD.org>

fix ln to accept -f again. Thanks Bruce. Seems that Joe Grosch isn't
quite as safe as I thought. I will have to look much closer on his
patches. Damn.


# 3a155232 20-Sep-1994 Poul-Henning Kamp <phk@FreeBSD.org>

/home/phk/jg


# 4b88c807 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite bin Sources