HIDE_OPTION,
HYPERLINK_OPTION,
INDICATOR_STYLE_OPTION,
+ NULL_OPTION,
QUOTING_STYLE_OPTION,
SHOW_CONTROL_CHARS_OPTION,
SI_OPTION,
{"human-readable", no_argument, NULL, 'h'},
{"inode", no_argument, NULL, 'i'},
{"kibibytes", no_argument, NULL, 'k'},
+ {"null", no_argument, NULL, NULL_OPTION},
{"numeric-uid-gid", no_argument, NULL, 'n'},
{"no-group", no_argument, NULL, 'G'},
{"hide-control-chars", no_argument, NULL, 'q'},
assert (sb.st_ino == di.st_ino);
}
+static char eolbyte = '\n';
+
/* Write to standard output PREFIX, followed by the quoting style and
a space-separated list of the integers stored in OS all on one line. */
intmax_t p = pos[i];
printf (" %"PRIdMAX, p);
}
- putchar ('\n');
+ putchar (eolbyte);
}
}
{
print_current_files ();
if (pending_dirs)
- dired_outbyte ('\n');
+ dired_outbyte (eolbyte);
}
else if (n_files <= 1 && pending_dirs && pending_dirs->next == 0)
print_dir_name = false;
/* No need to free these since we're about to exit. */
dired_dump_obstack ("//DIRED//", &dired_obstack);
dired_dump_obstack ("//SUBDIRED//", &subdired_obstack);
- printf ("//DIRED-OPTIONS// --quoting-style=%s\n",
- quoting_style_args[get_quoting_style (filename_quoting_options)]);
+ printf ("//DIRED-OPTIONS// --quoting-style=%s%c",
+ quoting_style_args[get_quoting_style (filename_quoting_options)],
+ eolbyte);
}
if (LOOP_DETECT)
indicator_style_types);
break;
+ case NULL_OPTION:
+ eolbyte = 0;
+ break;
+
case QUOTING_STYLE_OPTION:
set_quoting_style (NULL,
XARGMATCH ("--quoting-style", optarg,
if (recursive || print_dir_name)
{
if (!first)
- dired_outbyte ('\n');
+ dired_outbyte (eolbyte);
first = false;
dired_indent ();
free (absolute_name);
- dired_outstring (":\n");
+ dired_outbyte (':');
+ dired_outbyte (eolbyte);
}
/* Read the directory entries, and insert the subfiles into the 'cwd_file'
ST_NBLOCKSIZE, output_block_size);
char *pend = p + strlen (p);
*--p = ' ';
- *pend++ = '\n';
+ *pend++ = eolbyte;
dired_indent ();
dired_outstring (_("total"));
dired_outbuf (p, pend - p);
for (i = 0; i < cwd_n_used; i++)
{
print_file_name_and_frills (sorted_file[i], 0);
- putchar ('\n');
+ putchar (eolbyte);
}
break;
{
set_normal_color ();
print_long_format (sorted_file[i]);
- dired_outbyte ('\n');
+ dired_outbyte (eolbyte);
}
break;
}
indent (pos + name_length, pos + max_name_length);
pos += max_name_length;
}
- putchar ('\n');
+ putchar (eolbyte);
}
}
if (col == 0)
{
- putchar ('\n');
+ putchar (eolbyte);
pos = 0;
}
else
name_length = length_of_file_name_and_frills (f);
max_name_length = line_fmt->col_arr[col];
}
- putchar ('\n');
+ putchar (eolbyte);
}
/* Output name + SEP + ' '. */
else
{
pos = 0;
- separator = '\n';
+ separator = eolbyte;
}
putchar (sep);
print_file_name_and_frills (f, pos);
pos += len;
}
- putchar ('\n');
+ putchar (eolbyte);
}
/* Assuming cursor is at position FROM, indent up to position TO.
\n\
"), stdout);
fputs (_("\
+ --null end each output line with NUL, not newline\n\
-n, --numeric-uid-gid like -l, but list numeric user and group IDs\n\
-N, --literal print entry names without quoting\n\
-o like -l, but do not list group information\n\
--- /dev/null
+#!/bin/sh
+# Verify behavior of ls --null.
+
+# Copyright 2021 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ ls
+
+mkdir dir && touch dir/a dir/b dir/cc || framework_failure_
+
+LC_ALL=C ls --null dir >out || fail=1
+tr '\n' '\0' <<EOF >exp
+a
+b
+cc
+EOF
+
+compare exp out || fail=1
+
+Exit $fail