[Midnightbsd-cvs] src [11265] trunk/usr.bin/uniq/uniq.c: sync uniq with freebsd 10 stable
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Jul 3 19:54:51 EDT 2018
Revision: 11265
http://svnweb.midnightbsd.org/src/?rev=11265
Author: laffer1
Date: 2018-07-03 19:54:50 -0400 (Tue, 03 Jul 2018)
Log Message:
-----------
sync uniq with freebsd 10 stable
Modified Paths:
--------------
trunk/usr.bin/uniq/Makefile
trunk/usr.bin/uniq/uniq.1
trunk/usr.bin/uniq/uniq.c
Added Paths:
-----------
trunk/usr.bin/uniq/tests/
trunk/usr.bin/uniq/tests/Makefile
trunk/usr.bin/uniq/tests/Makefile.depend
Property Changed:
----------------
trunk/usr.bin/uniq/uniq.1
Modified: trunk/usr.bin/uniq/Makefile
===================================================================
--- trunk/usr.bin/uniq/Makefile 2018-07-03 23:54:09 UTC (rev 11264)
+++ trunk/usr.bin/uniq/Makefile 2018-07-03 23:54:50 UTC (rev 11265)
@@ -1,6 +1,13 @@
+# $MidnightBSD$
# @(#)Makefile 8.1 (Berkeley) 6/6/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/uniq/Makefile 314817 2017-03-07 01:52:50Z ngie $
+.include <bsd.own.mk>
+
PROG= uniq
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
Added: trunk/usr.bin/uniq/tests/Makefile
===================================================================
--- trunk/usr.bin/uniq/tests/Makefile (rev 0)
+++ trunk/usr.bin/uniq/tests/Makefile 2018-07-03 23:54:50 UTC (rev 11265)
@@ -0,0 +1,17 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/uniq/tests/Makefile 314817 2017-03-07 01:52:50Z ngie $
+
+NETBSD_ATF_TESTS_SH= uniq_test
+
+FILES+= d_basic.in
+FILES+= d_basic.out
+FILES+= d_counts.out
+FILES+= d_input.in
+FILES+= d_show_duplicates.out
+FILES+= d_show_uniques.out
+
+BINDIR= ${TESTSDIR}
+
+.include <netbsd-tests.test.mk>
+
+.include <bsd.test.mk>
Property changes on: trunk/usr.bin/uniq/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.bin/uniq/tests/Makefile.depend
===================================================================
--- trunk/usr.bin/uniq/tests/Makefile.depend (rev 0)
+++ trunk/usr.bin/uniq/tests/Makefile.depend 2018-07-03 23:54:50 UTC (rev 11265)
@@ -0,0 +1,12 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/uniq/tests/Makefile.depend 312127 2017-01-14 06:51:31Z ngie $
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
Property changes on: trunk/usr.bin/uniq/tests/Makefile.depend
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/usr.bin/uniq/uniq.1
===================================================================
--- trunk/usr.bin/uniq/uniq.1 2018-07-03 23:54:09 UTC (rev 11264)
+++ trunk/usr.bin/uniq/uniq.1 2018-07-03 23:54:50 UTC (rev 11265)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -29,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)uniq.1 8.1 (Berkeley) 6/6/93
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/uniq/uniq.1 216370 2010-12-11 08:32:16Z joel $
.\"
.Dd December 17, 2009
.Dt UNIQ 1
Property changes on: trunk/usr.bin/uniq/uniq.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/uniq/uniq.c
===================================================================
--- trunk/usr.bin/uniq/uniq.c 2018-07-03 23:54:09 UTC (rev 11264)
+++ trunk/usr.bin/uniq/uniq.c 2018-07-03 23:54:50 UTC (rev 11265)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -41,33 +42,49 @@
static char sccsid[] = "@(#)uniq.c 8.3 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
- "$MidnightBSD$";
+ "$FreeBSD: stable/10/usr.bin/uniq/uniq.c 280250 2015-03-19 12:32:48Z rwatson $";
#endif /* not lint */
+#include <sys/capsicum.h>
+
#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <limits.h>
#include <locale.h>
+#include <nl_types.h>
#include <stdint.h>
#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <wctype.h>
-int cflag, dflag, uflag, iflag;
-int numchars, numfields, repeats;
+static int cflag, dflag, uflag, iflag;
+static int numchars, numfields, repeats;
-FILE *file(const char *, const char *);
-wchar_t *convert(const char *);
-int inlcmp(const char *, const char *);
-void show(FILE *, const char *);
-wchar_t *skip(wchar_t *);
-void obsolete(char *[]);
+static FILE *file(const char *, const char *);
+static wchar_t *convert(const char *);
+static int inlcmp(const char *, const char *);
+static void show(FILE *, const char *);
+static wchar_t *skip(wchar_t *);
+static void obsolete(char *[]);
static void usage(void);
+static void
+strerror_init(void)
+{
+
+ /*
+ * Cache NLS data before entering capability mode.
+ * XXXPJD: There should be strerror_init() and strsignal_init() in libc.
+ */
+ (void)catopen("libc", NL_CAT_LOCALE);
+}
+
int
main (int argc, char *argv[])
{
@@ -77,6 +94,7 @@
size_t prevbuflen, thisbuflen, b1;
char *prevline, *thisline, *p;
const char *ifn;
+ cap_rights_t rights;
(void) setlocale(LC_ALL, "");
@@ -128,9 +146,34 @@
ofp = stdout;
if (argc > 0 && strcmp(argv[0], "-") != 0)
ifp = file(ifn = argv[0], "r");
+ cap_rights_init(&rights, CAP_FSTAT, CAP_READ);
+ if (cap_rights_limit(fileno(ifp), &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for %s", ifn);
+ cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE);
if (argc > 1)
ofp = file(argv[1], "w");
+ else
+ cap_rights_set(&rights, CAP_IOCTL);
+ if (cap_rights_limit(fileno(ofp), &rights) < 0 && errno != ENOSYS) {
+ err(1, "unable to limit rights for %s",
+ argc > 1 ? argv[1] : "stdout");
+ }
+ if (cap_rights_is_set(&rights, CAP_IOCTL)) {
+ unsigned long cmd;
+ cmd = TIOCGETA; /* required by isatty(3) in printf(3) */
+
+ if (cap_ioctls_limit(fileno(ofp), &cmd, 1) < 0 &&
+ errno != ENOSYS) {
+ err(1, "unable to limit ioctls for %s",
+ argc > 1 ? argv[1] : "stdout");
+ }
+ }
+
+ strerror_init();
+ if (cap_enter() < 0 && errno != ENOSYS)
+ err(1, "unable to enter capability mode");
+
prevbuflen = thisbuflen = 0;
prevline = thisline = NULL;
@@ -184,7 +227,7 @@
exit(0);
}
-wchar_t *
+static wchar_t *
convert(const char *str)
{
size_t n;
@@ -218,7 +261,7 @@
return (ret);
}
-int
+static int
inlcmp(const char *s1, const char *s2)
{
int c1, c2;
@@ -241,7 +284,7 @@
* Output a line depending on the flags and number of repetitions
* of the line.
*/
-void
+static void
show(FILE *ofp, const char *str)
{
@@ -251,7 +294,7 @@
(void)fprintf(ofp, "%s", str);
}
-wchar_t *
+static wchar_t *
skip(wchar_t *str)
{
int nchars, nfields;
@@ -267,7 +310,7 @@
return(str);
}
-FILE *
+static FILE *
file(const char *name, const char *mode)
{
FILE *fp;
@@ -277,7 +320,7 @@
return(fp);
}
-void
+static void
obsolete(char *argv[])
{
int len;
More information about the Midnightbsd-cvs
mailing list