Commit Graph

50 Commits

Author SHA1 Message Date
ian
23ebeca83d Support --all-repeats in uniq(1) for compatibility with gnu coreutils.
This adds a new -D/--all-repeats option to uniq(1), which outputs each copy
of any repeated lines (as opposed to a single copy of a repeated line). You
can specify a separator option to output a blank line before or after each
group of repeated lines. This adds compatibility with the GNU coreutils
version of uniq(1).

This change also re-groups the -c, -d, -D, -u options in the usage display
and man page to indicate that they are mutally exclusive of each other. This
matches the posix/opengroup definition of uniq(1) command line args. Note
that this change does NOT actually enforce the mutual exclusion in the code,
for now, it simply documents that the arguments should be considered
exclusive with each other.

Differential Revision:	https://reviews.freebsd.org/D22262
2019-12-15 18:05:18 +00:00
oshogbo
b60d6a5607 capsicum: use a new capsicum helpers in tools
Use caph_{rights,ioctls,fcntls}_limit to simplify the code.
2018-11-04 19:24:49 +00:00
oshogbo
090724585b Use capsicum helpers to cache NLS data. 2018-06-20 00:13:09 +00:00
oshogbo
8acf9b1609 Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0.
No functional change intended.
2018-06-19 23:43:14 +00:00
kevans
01c874c7a2 uniq(1): Add some long options
These match GNU uniq(1) where appropriate for compatibility's sake.

While here, re-sort options alphabetically by the short-option.

MFC after:	1 month
2018-05-02 01:17:08 +00:00
pfg
872b698bd4 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.
2017-11-20 19:49:47 +00:00
emaste
fdf3f96c49 uniq: allow -c to be used with -d or -u
Bring in some bits from NetBSD and lift the restriction in uniq(1) that
-c cannot be used with the -d and -u options.  This restriction seems
unnecessary and is supported at least by GNU, OpenBSD, and NetBSD.  Lift
the restriction and simplify the show() logic a little bit to maintain
functionality when -c is provided with -d/-u.

Also with this change, -d and -u are now actually a mutually exclusive,
albeit valid, combination.  Given that they both indicate opposite
behavior, uniq(1) will no longer output anything if both -d and -u are
supplied.  This is in line with NetBSD as well as GNU.

Adjust the man page and usage() to reflect that -c is its own standalone
option.

PR:		200553
Submitted by:	Kyle Evans <kevans91@ksu.edu>
Reviewed by:	cem, emaste
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D10694
2017-05-15 20:18:14 +00:00
imp
7e6cabd06e 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
2017-02-28 23:42:47 +00:00
bapt
4ecca13b4c Remove usage of _WITH_GETLINE from usr.bin 2016-07-30 01:07:47 +00:00
rwatson
a400e9c007 Update most userspace consumers of capability.h to use capsicum.h instead.
auditdistd is not updated as I will make the change upstream and then do a
vendor import sometime in the next week or two.

MFC after:	3 weeks
2014-03-16 11:04:44 +00:00
pjd
029a6f5d92 Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.

The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.

The structure definition looks like this:

	struct cap_rights {
		uint64_t	cr_rights[CAP_RIGHTS_VERSION + 2];
	};

The initial CAP_RIGHTS_VERSION is 0.

The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.

The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.

To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.

	#define	CAP_PDKILL	CAPRIGHT(1, 0x0000000000000800ULL)

We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:

	#define	CAP_LOOKUP	CAPRIGHT(0, 0x0000000000000400ULL)
	#define	CAP_FCHMOD	CAPRIGHT(0, 0x0000000000002000ULL)

	#define	CAP_FCHMODAT	(CAP_FCHMOD | CAP_LOOKUP)

There is new API to manage the new cap_rights_t structure:

	cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
	void cap_rights_set(cap_rights_t *rights, ...);
	void cap_rights_clear(cap_rights_t *rights, ...);
	bool cap_rights_is_set(const cap_rights_t *rights, ...);

	bool cap_rights_is_valid(const cap_rights_t *rights);
	void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
	void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
	bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);

Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:

	cap_rights_t rights;

	cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);

There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:

	#define	cap_rights_set(rights, ...)				\
		__cap_rights_set((rights), __VA_ARGS__, 0ULL)
	void __cap_rights_set(cap_rights_t *rights, ...);

Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:

	cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);

Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.

This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.

Sponsored by:	The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
pjd
f2d723e2cd Close uniq(1) in the capability mode sandbox and limit descriptors using
capability rights.
2013-07-18 22:11:27 +00:00
ed
7842959704 Add missing static keywords to uniq(1) 2011-11-06 08:18:11 +00:00
joel
29af67e52c Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with:	imp, rwatson
2010-12-11 08:32:16 +00:00
ache
0cc78f7ab0 Add SIZE_MAX overflow check 2010-03-09 21:06:01 +00:00
ache
b17e796fd7 1) Reimplement (differently) unlimited line length restricted in prev.
commit.

2) Honor missing the very last \n (if absent) on output.
2010-03-08 19:40:22 +00:00
ache
f28c83324f Remove vestiges of old %-format which prevents build on amd64 2010-03-06 22:38:38 +00:00
ache
85448eebc0 1) Rewrite input processing to not exit with error on the first EILSEQ found
in the input data but fallback to "binary equal" check instead.

POSIX says: "The input file shall be a text file", nothing more,
so the text file with illegal sequence is valid input.
BTW, GNU sort does not fails on EILSEQ too.

2) Speedup input processing a bit in complex cases like skipping fields,
chars or ignore case.

3) Enforce the implied LINE_MAX limit (from POSIX definition of "text file"
and POSIX uniq(1) description).
2010-03-06 19:21:57 +00:00
jh
060a87e0f5 Sync getline() with comm(1):
- Prevent overflowing of the buffer length variable in getline() by
   limiting its maximum value.
 - Exit if reallocf(3) fails in getline(). Failure was silently
   considered as end-of-file.

Reviewed by:	ghelmer
Approved by:	trasz (mentor)
2009-12-17 17:03:47 +00:00
ghelmer
56c7e4a9b4 Fix truncation of lines at LINE_MAX characters by dynamically
extending line buffers.

PR:		bin/76578
2008-02-08 23:04:13 +00:00
jmallett
c449c9befa Fix typo. 2007-05-17 00:19:56 +00:00
jmallett
070c749233 o) Correct for missing whitespace.
o) We don't need to check if ifp == stdin to give the filename, since we already
   know that ifn will be "stdin" if it is.
2007-05-17 00:18:01 +00:00
jmallett
4f0511a3a8 Fix confusing misindentation of a closing-brace. (It goes with the switch, not
with the while.)
2007-05-17 00:11:58 +00:00
tjr
d7872e5e5f Remove a bogus check that caused empty lines not to be counted when the
-c option was given.

Noticed by:	sf
2004-09-14 12:01:18 +00:00
tjr
ab71ec88b7 Add support for multibyte characters. 2004-07-02 23:43:05 +00:00
dwmalone
b4339b74ad ANSIify function definitions.
Add some constness to avoid some warnings.
Remove use register keyword.
Deal with missing/unneeded extern/prototypes.
Some minor type changes/casts to avoid warnings.

Reviewed by:	md5
2002-09-04 23:29:10 +00:00
tjr
3594350f00 Use err instead of errx when malloc fails. "malloc" is not a helpful
error message.
2002-07-05 09:28:13 +00:00
tjr
37c7624aa9 Skip fields in the manner required by POSIX, and the way V7 did it.
MFC after:	1 week
2002-06-21 07:59:31 +00:00
tjr
61c21ff1cf Newline characters should not participate in line comparisons. Only apparent
when -s is used or the last line of the file is missing a newline.
Noticed by the textutils test suite.

MFC after:	1 week
2002-06-21 07:08:34 +00:00
ache
37d7c3a7df Back out rev 1.19 because
1) It breaks uniq for real life languages when "substitute" directive used in
the collating table.
2) It breaks uniq usage in tool chain with other localized utilities which
use collate.
3) To follow LC_COLLATE it is directly allowed for uniq
by POSIX P1003.1 Draft7 (7.3.2). It means that rev 1.19 gains no additional
POSIX conformance.
2002-06-06 13:44:14 +00:00
tjr
264da240fc Compare lines with strcmp(), not strcoll(). We are interested only in
equality, not ordering.
2002-06-06 03:13:08 +00:00
tjr
050d703846 Sync usage() with manual page synopsis. 2002-06-06 03:05:30 +00:00
tjr
60d1ab01d7 Accept an input file name of "-" to mean standard input, as required by
P1003.2.
2002-05-30 00:07:14 +00:00
tjr
2d9a2285ef Fields should be separated by <blank>s, not <space>s according to P1003.2. 2002-05-29 23:55:44 +00:00
tjr
31d09977d0 Don't bother trying to handle "-" arguments ourselves, getopt(3) already
does this for us.
2002-05-29 23:52:55 +00:00
ache
ef9121555f Use LC_ALL to pick collate
Noticed by:	tjr
2002-04-19 08:16:01 +00:00
imp
0b20191705 remove __P 2002-03-22 01:42:45 +00:00
dwmalone
383583bd4f Warns cleanups. Add FreeBSD ID to Makefile. 2001-12-03 21:37:35 +00:00
ache
91440b61a3 fix fatal typo 1999-12-10 13:06:53 +00:00
ache
25e78d8b60 toupper -> tolower to match changed behaviour of new grep case fold 1999-10-29 05:11:06 +00:00
ache
d8f93ede38 Cosmetique: use standard prototypes scheme
Back out prev. change: toupper is more compatible with sort -f
1999-10-24 04:41:31 +00:00
ache
c870ad3624 toupper->tolower to match what strcasecmp does 1999-10-24 04:21:42 +00:00
ache
9fbc2f9470 Use strcoll to provide the same results as sort and comm
Use LINE_MAX for max line size (as comm does)
1999-10-24 04:08:15 +00:00
peter
3b842d34e8 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
ache
81b26c0896 Localize it 1998-03-08 20:56:43 +00:00
joerg
caa2e7e2da Teach comm(1) and uniq(1) about an option for case-insensitive work.
PR:		3042
Submitted by:	graphix@iastate.edu (Kent Vander Velden)
1997-09-07 15:09:22 +00:00
charnier
16f9b719d4 Use err(3) instead of local redefinition. 1997-08-21 06:51:10 +00:00
imp
141381e1cb compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-29 04:34:07 +00:00
peter
297505f8fa Import some parts of CSRG 4.4BSD-Lite2 usr.bin sources to fix tree build. 1997-03-11 13:08:12 +00:00
rgrimes
f9ab90d9d6 BSD 4.4 Lite Usr.bin Sources 1994-05-27 12:33:43 +00:00