CVS commit: src/usr.bin/env

2020-02-08 Thread Leonardo Taccari
Module Name:src
Committed By:   leot
Date:   Sat Feb  8 11:10:08 UTC 2020

Modified Files:
src/usr.bin/env: env.1

Log Message:
Fix a typo (extra `s')


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/env/env.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/env/env.1
diff -u src/usr.bin/env/env.1:1.14 src/usr.bin/env/env.1:1.15
--- src/usr.bin/env/env.1:1.14	Sat Feb  8 11:02:07 2020
+++ src/usr.bin/env/env.1	Sat Feb  8 11:10:08 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: env.1,v 1.14 2020/02/08 11:02:07 kamil Exp $
+.\"	$NetBSD: env.1,v 1.15 2020/02/08 11:10:08 leot Exp $
 .\"
 .\" Copyright (c) 1980, 1990 The Regents of the University of California.
 .\" All rights reserved.
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	from: @(#)printenv.1	6.7 (Berkeley) 7/28/91
-.\"	$NetBSD: env.1,v 1.14 2020/02/08 11:02:07 kamil Exp $
+.\"	$NetBSD: env.1,v 1.15 2020/02/08 11:10:08 leot Exp $
 .\"
 .Dd February 8, 2020
 .Dt ENV 1
@@ -158,7 +158,7 @@ The
 .Fl u
 and
 .Fl 0
-optionss first appeared in
+options first appeared in
 .Nx 10 .
 .Sh BUGS
 .Nm



CVS commit: src/usr.bin/env

2020-02-08 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb  8 11:02:07 UTC 2020

Modified Files:
src/usr.bin/env: env.1 env.c

Log Message:
Implement env(1) -0

-0  End each output line with NUL, not newline.

FreeBSD and GNU env(1) implement -0 which is used in 3rd party scripts.

This change is based on the FreeBSD code.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/env/env.1
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/env/env.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/env/env.1
diff -u src/usr.bin/env/env.1:1.13 src/usr.bin/env/env.1:1.14
--- src/usr.bin/env/env.1:1.13	Sat Feb  8 10:30:22 2020
+++ src/usr.bin/env/env.1	Sat Feb  8 11:02:07 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: env.1,v 1.13 2020/02/08 10:30:22 kamil Exp $
+.\"	$NetBSD: env.1,v 1.14 2020/02/08 11:02:07 kamil Exp $
 .\"
 .\" Copyright (c) 1980, 1990 The Regents of the University of California.
 .\" All rights reserved.
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	from: @(#)printenv.1	6.7 (Berkeley) 7/28/91
-.\"	$NetBSD: env.1,v 1.13 2020/02/08 10:30:22 kamil Exp $
+.\"	$NetBSD: env.1,v 1.14 2020/02/08 11:02:07 kamil Exp $
 .\"
 .Dd February 8, 2020
 .Dt ENV 1
@@ -40,7 +40,7 @@
 .Nd set and print environment
 .Sh SYNOPSIS
 .Nm
-.Op Fl i
+.Op Fl 0i
 .Op Fl u Ar name
 .Op Ar name=value ...
 .Oo
@@ -86,10 +86,17 @@ If no
 .Ar utility
 is specified,
 .Nm
-prints out the names and values
-of the variables in the environment, with one
+prints out the names and values of the variables in the environment.
+Each
 .Ar name=value
-pair per line.
+pair is separated by a new line unless
+.Fl 0
+is specified, in which case name/value pairs are separated by NUL.
+Both
+.Fl 0
+and
+.Ar utility
+must not be specified together.
 .Sh EXIT STATUS
 .Nm
 exits with one of the following values:
@@ -111,6 +118,11 @@ was invoked, but failed in some way;
 see its manual page for more information.
 In this case the exit code is returned by the utility itself, not
 .Nm .
+.It 125
+.Ar utility
+was specified together with the
+.Fl 0
+option.
 .It 126
 .Ar utility
 was found, but could not be invoked.
@@ -125,7 +137,9 @@ option has been deprecated but is still 
 .Pp
 The
 .Fl u
-option is a non-standard extension.
+and
+.Fl 0
+options are non-standard extensions.
 .Sh SEE ALSO
 .Xr execvp 3 ,
 .Xr environ 7
@@ -142,7 +156,9 @@ command appeared in
 .Pp
 The
 .Fl u
-option first appeared in
+and
+.Fl 0
+optionss first appeared in
 .Nx 10 .
 .Sh BUGS
 .Nm

Index: src/usr.bin/env/env.c
diff -u src/usr.bin/env/env.c:1.22 src/usr.bin/env/env.c:1.23
--- src/usr.bin/env/env.c:1.22	Sat Feb  8 10:36:02 2020
+++ src/usr.bin/env/env.c	Sat Feb  8 11:02:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: env.c,v 1.22 2020/02/08 10:36:02 kamil Exp $	*/
+/*	$NetBSD: env.c,v 1.23 2020/02/08 11:02:07 kamil Exp $	*/
 /*
  * Copyright (c) 1988, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 
 #ifndef lint
 /*static char sccsid[] = "@(#)env.c	8.3 (Berkeley) 4/2/94";*/
-__RCSID("$NetBSD: env.c,v 1.22 2020/02/08 10:36:02 kamil Exp $");
+__RCSID("$NetBSD: env.c,v 1.23 2020/02/08 11:02:07 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -54,15 +54,19 @@ extern char **environ;
 int
 main(int argc, char **argv)
 {
-	char **ep;
+	char **ep, term;
 	char *cleanenv[1];
 	int ch;
 
 	setprogname(*argv);
 	(void)setlocale(LC_ALL, "");
 
-	while ((ch = getopt(argc, argv, "-iu:")) != -1)
+	term = '\n';
+	while ((ch = getopt(argc, argv, "-0iu:")) != -1)
 		switch((char)ch) {
+		case '0':
+			term = '\0';
+			break;
 		case '-':			/* obsolete */
 		case 'i':
 			environ = cleanenv;
@@ -82,7 +86,11 @@ main(int argc, char **argv)
 
 	if (*argv) {
 		/* return 127 if the command to be run could not be found; 126
-		   if the command was found but could not be invoked */
+		   if the command was found but could not be invoked; 125 if
+		   -0 was specified with utility.*/
+
+		if (term == '\0')
+			errx(125, "cannot specify command with -0");
 
 		(void)execvp(*argv, argv);
 		err((errno == ENOENT) ? 127 : 126, "%s", *argv);
@@ -90,7 +98,7 @@ main(int argc, char **argv)
 	}
 
 	for (ep = environ; *ep; ep++)
-		(void)printf("%s\n", *ep);
+		(void)printf("%s%c", *ep, term);
 
 	exit(0);
 }
@@ -99,7 +107,7 @@ static void
 usage(void)
 {
 	(void)fprintf(stderr,
-	"Usage: %s [-i] [-u name] [name=value ...] [command]\n",
+	"Usage: %s [-0i] [-u name] [name=value ...] [command]\n",
 	getprogname());
 	exit(1);
 }



CVS commit: src/usr.bin/env

2020-02-08 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb  8 10:36:02 UTC 2020

Modified Files:
src/usr.bin/env: env.c

Log Message:
Add CVS Id tag and switch __attribute__ to __dead.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/env/env.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/env/env.c
diff -u src/usr.bin/env/env.c:1.21 src/usr.bin/env/env.c:1.22
--- src/usr.bin/env/env.c:1.21	Sat Feb  8 10:30:22 2020
+++ src/usr.bin/env/env.c	Sat Feb  8 10:36:02 2020
@@ -1,3 +1,4 @@
+/*	$NetBSD: env.c,v 1.22 2020/02/08 10:36:02 kamil Exp $	*/
 /*
  * Copyright (c) 1988, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -35,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 
 #ifndef lint
 /*static char sccsid[] = "@(#)env.c	8.3 (Berkeley) 4/2/94";*/
-__RCSID("$NetBSD: env.c,v 1.21 2020/02/08 10:30:22 kamil Exp $");
+__RCSID("$NetBSD: env.c,v 1.22 2020/02/08 10:36:02 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -46,7 +47,7 @@ __RCSID("$NetBSD: env.c,v 1.21 2020/02/0
 #include 
 #include 
 
-static void usage(void) __attribute__((__noreturn__));
+static void usage(void) __dead;
 
 extern char **environ;
 



CVS commit: src/usr.bin/env

2020-02-08 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb  8 10:30:22 UTC 2020

Modified Files:
src/usr.bin/env: env.1 env.c

Log Message:
Implement env(1) -u

The option '-u name' causes removal of the name environment variable if
it is in the environment.  This is similar to the unset command in sh(1).
The value for name must not include the '=' character.

Add HISTORY section in the man page.

The -u argument is implemented by Linux, FreeBSD and Darwin.
The lack of -u in NetBSD is a cause for a frequent fallout in the LLVM
toolchain test-suite.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/env/env.1
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/env/env.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/env/env.1
diff -u src/usr.bin/env/env.1:1.12 src/usr.bin/env/env.1:1.13
--- src/usr.bin/env/env.1:1.12	Fri Jun  8 18:20:42 2007
+++ src/usr.bin/env/env.1	Sat Feb  8 10:30:22 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: env.1,v 1.12 2007/06/08 18:20:42 wiz Exp $
+.\"	$NetBSD: env.1,v 1.13 2020/02/08 10:30:22 kamil Exp $
 .\"
 .\" Copyright (c) 1980, 1990 The Regents of the University of California.
 .\" All rights reserved.
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	from: @(#)printenv.1	6.7 (Berkeley) 7/28/91
-.\"	$NetBSD: env.1,v 1.12 2007/06/08 18:20:42 wiz Exp $
+.\"	$NetBSD: env.1,v 1.13 2020/02/08 10:30:22 kamil Exp $
 .\"
-.Dd June 8, 2007
+.Dd February 8, 2020
 .Dt ENV 1
 .Os
 .Sh NAME
@@ -41,6 +41,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl i
+.Op Fl u Ar name
 .Op Ar name=value ...
 .Oo
 .Ar utility
@@ -66,6 +67,21 @@ causes
 to completely ignore the environment
 it inherits.
 .Pp
+The option
+.Sq Fl u Ar name
+causes removal of the
+.Ar name
+environment variable if it is in the environment.
+This is similar to the
+.Ic unset
+command in
+.Xr sh 1 .
+The value for
+.Ar name
+must not include the
+.Ql =
+character.
+.Pp
 If no
 .Ar utility
 is specified,
@@ -106,6 +122,10 @@ could not be found.
 The historic
 .Fl
 option has been deprecated but is still supported in this implementation.
+.Pp
+The
+.Fl u
+option is a non-standard extension.
 .Sh SEE ALSO
 .Xr execvp 3 ,
 .Xr environ 7
@@ -114,6 +134,16 @@ The
 .Nm
 utility conforms to
 .St -p1003.2-92 .
+.Sh HISTORY
+The
+.Nm
+command appeared in
+.Bx 4.4 .
+.Pp
+The
+.Fl u
+option first appeared in
+.Nx 10 .
 .Sh BUGS
 .Nm
 doesn't handle commands with equal

Index: src/usr.bin/env/env.c
diff -u src/usr.bin/env/env.c:1.20 src/usr.bin/env/env.c:1.21
--- src/usr.bin/env/env.c:1.20	Tue Nov 16 02:53:49 2010
+++ src/usr.bin/env/env.c	Sat Feb  8 10:30:22 2020
@@ -35,7 +35,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 
 #ifndef lint
 /*static char sccsid[] = "@(#)env.c	8.3 (Berkeley) 4/2/94";*/
-__RCSID("$NetBSD: env.c,v 1.20 2010/11/16 02:53:49 christos Exp $");
+__RCSID("$NetBSD: env.c,v 1.21 2020/02/08 10:30:22 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -60,13 +60,17 @@ main(int argc, char **argv)
 	setprogname(*argv);
 	(void)setlocale(LC_ALL, "");
 
-	while ((ch = getopt(argc, argv, "-i")) != -1)
+	while ((ch = getopt(argc, argv, "-iu:")) != -1)
 		switch((char)ch) {
 		case '-':			/* obsolete */
 		case 'i':
 			environ = cleanenv;
 			cleanenv[0] = NULL;
 			break;
+		case 'u':
+			if (unsetenv(optarg) == -1)
+errx(EXIT_FAILURE, "unsetenv %s", optarg);
+			break;
 		case '?':
 		default:
 			usage();
@@ -93,7 +97,8 @@ main(int argc, char **argv)
 static void
 usage(void)
 {
-	(void)fprintf(stderr, "Usage: %s [-i] [name=value ...] [command]\n",
+	(void)fprintf(stderr,
+	"Usage: %s [-i] [-u name] [name=value ...] [command]\n",
 	getprogname());
 	exit(1);
 }



CVS commit: src/usr.bin/env

2010-11-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Nov 16 02:53:49 UTC 2010

Modified Files:
src/usr.bin/env: env.c

Log Message:
minor KNF nits.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/env/env.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/env/env.c
diff -u src/usr.bin/env/env.c:1.19 src/usr.bin/env/env.c:1.20
--- src/usr.bin/env/env.c:1.19	Sat Oct 16 07:13:52 2010
+++ src/usr.bin/env/env.c	Mon Nov 15 21:53:49 2010
@@ -35,7 +35,7 @@
 
 #ifndef lint
 /*static char sccsid[] = @(#)env.c	8.3 (Berkeley) 4/2/94;*/
-__RCSID($NetBSD: env.c,v 1.19 2010/10/16 11:13:52 njoly Exp $);
+__RCSID($NetBSD: env.c,v 1.20 2010/11/16 02:53:49 christos Exp $);
 #endif /* not lint */
 
 #include err.h
@@ -46,8 +46,7 @@
 #include locale.h
 #include errno.h
 
-int	main(int, char **);
-static void usage(void);
+static void usage(void) __attribute__((__noreturn__));
 
 extern char **environ;
 
@@ -58,7 +57,8 @@
 	char *cleanenv[1];
 	int ch;
 
-	setlocale(LC_ALL, );
+	setprogname(*argv);
+	(void)setlocale(LC_ALL, );
 
 	while ((ch = getopt(argc, argv, -i)) != -1)
 		switch((char)ch) {
@@ -79,7 +79,7 @@
 		/* return 127 if the command to be run could not be found; 126
 		   if the command was found but could not be invoked */
 
-		execvp(*argv, argv);
+		(void)execvp(*argv, argv);
 		err((errno == ENOENT) ? 127 : 126, %s, *argv);
 		/* NOTREACHED */
 	}
@@ -93,6 +93,7 @@
 static void
 usage(void)
 {
-	(void)fprintf(stderr, usage: env [-i] [name=value ...] [command]\n);
+	(void)fprintf(stderr, Usage: %s [-i] [name=value ...] [command]\n,
+	getprogname());
 	exit(1);
 }



CVS commit: src/usr.bin/env

2010-10-16 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Sat Oct 16 11:13:52 UTC 2010

Modified Files:
src/usr.bin/env: env.c

Log Message:
Do use putenv(3) to handle the provided strings directly, instead of
setenv(3) which need string splitting and later reassembly.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/env/env.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/env/env.c
diff -u src/usr.bin/env/env.c:1.18 src/usr.bin/env/env.c:1.19
--- src/usr.bin/env/env.c:1.18	Fri Oct 15 19:35:08 2010
+++ src/usr.bin/env/env.c	Sat Oct 16 11:13:52 2010
@@ -35,7 +35,7 @@
 
 #ifndef lint
 /*static char sccsid[] = @(#)env.c	8.3 (Berkeley) 4/2/94;*/
-__RCSID($NetBSD: env.c,v 1.18 2010/10/15 19:35:08 jschauma Exp $);
+__RCSID($NetBSD: env.c,v 1.19 2010/10/16 11:13:52 njoly Exp $);
 #endif /* not lint */
 
 #include err.h
@@ -54,7 +54,7 @@
 int
 main(int argc, char **argv)
 {
-	char **ep, *p;
+	char **ep;
 	char *cleanenv[1];
 	int ch;
 
@@ -72,8 +72,8 @@
 			usage();
 		}
 
-	for (argv += optind; *argv  (p = strchr(*argv, '=')); ++argv)
-		(void)setenv(*argv, ++p, 1);
+	for (argv += optind; *argv  strchr(*argv, '=') != NULL; ++argv)
+		(void)putenv(*argv);
 
 	if (*argv) {
 		/* return 127 if the command to be run could not be found; 126



CVS commit: src/usr.bin/env

2010-10-15 Thread Jan Schaumann
Module Name:src
Committed By:   jschauma
Date:   Fri Oct 15 19:35:09 UTC 2010

Modified Files:
src/usr.bin/env: env.c

Log Message:
remove duplicate 'was' in a comment


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/env/env.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/env/env.c
diff -u src/usr.bin/env/env.c:1.17 src/usr.bin/env/env.c:1.18
--- src/usr.bin/env/env.c:1.17	Mon Jul 21 14:19:22 2008
+++ src/usr.bin/env/env.c	Fri Oct 15 19:35:08 2010
@@ -35,7 +35,7 @@
 
 #ifndef lint
 /*static char sccsid[] = @(#)env.c	8.3 (Berkeley) 4/2/94;*/
-__RCSID($NetBSD: env.c,v 1.17 2008/07/21 14:19:22 lukem Exp $);
+__RCSID($NetBSD: env.c,v 1.18 2010/10/15 19:35:08 jschauma Exp $);
 #endif /* not lint */
 
 #include err.h
@@ -77,7 +77,7 @@
 
 	if (*argv) {
 		/* return 127 if the command to be run could not be found; 126
-		   if the command was was found but could not be invoked */
+		   if the command was found but could not be invoked */
 
 		execvp(*argv, argv);
 		err((errno == ENOENT) ? 127 : 126, %s, *argv);