* NEWS: Mention the improvement.
* src/env.c (main): With -0, set output to binary mode.
* src/printenv.c (main): Likewise.
---
NEWS | 3 +++
src/env.c | 3 +++
src/printenv.c | 4 ++++
3 files changed, 10 insertions(+)
diff --git a/NEWS b/NEWS
index d62dde3d8..797cc82ff 100644
--- a/NEWS
+++ b/NEWS
@@ -100,6 +100,9 @@ GNU coreutils NEWS -*-
outline -*-
'df', 'du', 'ls', 'od', 'pr', and 'sort' now escape invalid arguments in
error
messages for options expecting an integer.
+ 'env -0, and 'printenv -0' now explicitly set binary mode on output
+ so that no CRLF translation is done on output.
+
'install -C' will now avoid updating file metadata when the destination
already has the appropriate ownership and permissions.
diff --git a/src/env.c b/src/env.c
index 6a2b5eb54..e034650fa 100644
--- a/src/env.c
+++ b/src/env.c
@@ -1208,6 +1208,9 @@ main (int argc, char **argv)
{
char const terminator = opt_nul_terminate_output ? '\0' : '\n';
+ if (opt_nul_terminate_output)
+ xset_binary_mode (STDOUT_FILENO, O_BINARY);
+
/* Print the environment and exit. */
for (char *const *e = environ; *e; ++e)
print_envvar (*e, terminator, quote_output);
diff --git a/src/printenv.c b/src/printenv.c
index fbe35d5a6..540f56334 100644
--- a/src/printenv.c
+++ b/src/printenv.c
@@ -35,6 +35,7 @@
#include "argmatch.h" /* argmatch($QUOTING_STYLE). */
#include "system.h"
#include "printenv.h"
+#include "xbinary-io.h"
/* Exit status for syntax errors, etc. */
enum { PRINTENV_FAILURE = 2 };
@@ -126,6 +127,9 @@ main (int argc, char **argv)
bool ok;
char const terminator = opt_nul_terminate_output ? '\0' : '\n';
+ if (opt_nul_terminate_output)
+ xset_binary_mode (STDOUT_FILENO, O_BINARY);
+
if (optind >= argc)
{
for (char **env = environ; *env != NULL; ++env)
--
2.55.0