Commit Graph

43 Commits

Author SHA1 Message Date
eadler
0bf6af7fdd Add 'static' where able. 2013-06-02 17:55:00 +00:00
ed
f58d00c87a 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.
2011-10-31 08:59:17 +00:00
jilles
2a22eeb6a2 bin: Prefer strrchr() to rindex().
This removes the last index/rindex usage from /bin.
2011-03-15 22:22:11 +00:00
jilles
1a724f1dca 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
2010-04-21 21:57:03 +00:00
jilles
fd633ce008 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
2010-04-17 22:39:53 +00:00
jilles
afad68b5dc 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)
2009-07-19 17:35:23 +00:00
keramida
3902e2cc48 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
2008-06-07 09:37:30 +00:00
keramida
fd86b4a48c 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
2008-06-06 08:27:59 +00:00
ru
3371e72606 Express in the usage() and SYNOPSIS that -F depends on -s, and
that -f and -i are exclusive.
2007-11-17 21:01:22 +00:00
ru
4a831eed37 Swap "source"/"target" where appropriate, to match documentation. 2007-11-17 20:24:58 +00:00
glebius
e85d27fb5c 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>
2006-02-14 11:08:05 +00:00
ru
978b8f7f1d Sync program's usage() with manpage's SYNOPSIS. 2005-02-09 17:37:39 +00:00
imp
a76898b849 /*- or .\"- or #- to begin license clauses. 2005-01-10 08:39:26 +00:00
markm
4383f14801 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
obrien
eaf3fff90a Quiet warnings about copyright[]. 2003-05-01 16:58:57 +00:00
markm
c55a4dc47c Fix an easy WARNS. 2002-07-31 16:53:59 +00:00
obrien
c84c569bd1 Consistently use __FBSDID 2002-06-30 05:13:54 +00:00
tjr
c2f443c824 Check that snprintf() does not truncate the destination pathname when
linking into a directory.
2002-06-29 04:10:40 +00:00
tjr
a9256c24d5 Reject options, handle "--" end-of-options marker in link(1). 2002-05-30 00:57:38 +00:00
jedgar
818f9c0a64 Add semicolon to empty default case to silence warning. 2002-05-11 00:45:01 +00:00
markm
2e9a506a04 Fix warnings inspired by lint, a commercial lint and WARNS=4. 2002-02-22 21:11:03 +00:00
imp
50014e3541 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.
2002-02-02 06:48:10 +00:00
imp
bd38254e2e Use PATH_MAX in preference to MAXPATHLEN.
Also sort declarations per style(9) (big arrays come last) while I'm
in the area.
2001-05-29 17:27:56 +00:00
kris
87fe6c7de0 Silence WARNS=2 and BDECFLAGS on i386 and alpha
MFC After:	1 week
2001-05-20 04:54:15 +00:00
sobomax
d7706ae588 Bring in -h' compatability option and its alias -n' to match NetBSD and GNU
semantics.

style(9) Reviewed by:
Obtained from:	NetBSD
2001-04-26 17:15:57 +00:00
sheldonh
1c5470e606 Fix style bugs and inconsistencies introduced in rev 1.16.
Submitted by:	bde
2000-08-17 16:08:06 +00:00
imp
d5e7ddb4c9 Don't explicitly declare optarg and optind. These are declared in
unistd.h, which is already included.
2000-08-16 05:14:49 +00:00
sheldonh
d7fdad4baa 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
2000-08-14 08:48:55 +00:00
sheldonh
61c79b122e 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>
1999-12-20 16:13:47 +00:00
obrien
cb13e979b2 Add verbose processing flag. 1999-09-11 10:06:56 +00:00
peter
66312e4a8d $Id$ -> $FreeBSD$ 1999-08-27 23:15:48 +00:00
charnier
233c097df4 Correct use of .Nm. Add rcsid. 1998-05-15 06:19:05 +00:00
charnier
ae2a236f86 Cosmetic change in usage string. 1997-06-06 06:40:06 +00:00
imp
054f35c222 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-28 15:24:41 +00:00
peter
83b3c2c161 Revert $FreeBSD$ to $Id$ 1997-02-22 14:13:04 +00:00
jkh
808a36ef65 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.
1997-01-14 07:20:47 +00:00
steve
c5d0f9cb39 -Wall cleaning. 1996-12-14 06:08:03 +00:00
peter
cc2ce1192f 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)
1996-05-24 20:36:16 +00:00
bde
4bd4925bd2 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.
1994-12-06 18:50:44 +00:00
dg
8722740e7f Added $Id$ 1994-09-24 02:59:15 +00:00
phk
61ca3e5cab 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.
1994-09-20 07:24:51 +00:00
phk
2c9f4788e2 /home/phk/jg 1994-09-20 06:28:16 +00:00
rgrimes
e3cfc8ce61 BSD 4.4 Lite bin Sources 1994-05-26 06:18:55 +00:00