}
static int print_newline(FILE *f, const char *data, size_t l) {
- int fd;
-
assert(f);
assert(data || l == 0);
if (l > 0 && data[l-1] == '\n')
return 0;
- /* Don't bother unless this is a tty */
- fd = fileno(f);
- if (fd >= 0 && !isatty_safe(fd))
- return 0;
+ /* If not explicitly requested, don't bother if the output is not a tty */
+ if (arg_newline < 0) {
+ int fd = fileno(f);
+ if (fd >= 0 && !isatty_safe(fd))
+ return 0;
+ }
if (fputc('\n', f) != '\n')
return log_error_errno(errno, "Failed to write trailing newline: %m");
run_with_cred_compare "mycred:\n" "\n" cat mycred
run_with_cred_compare "mycred:foo" "foo" cat mycred
run_with_cred_compare "mycred:foo" "foofoofoo" cat mycred mycred mycred
-# Note: --newline= does nothing when stdout is not a tty, which is the case here
-run_with_cred_compare "mycred:foo" "foo" --newline=yes cat mycred
-run_with_cred_compare "mycred:foo" "foo" --newline=no cat mycred
run_with_cred_compare "mycred:foo" "foo" --newline=auto cat mycred
+run_with_cred_compare "mycred:foo" "foo" --newline=no cat mycred
+run_with_cred_compare "mycred:foo" "foo\n" --newline=yes cat mycred
run_with_cred_compare "mycred:foo" "foo" --transcode=no cat mycred
run_with_cred_compare "mycred:foo" "foo" --transcode=0 cat mycred
run_with_cred_compare "mycred:foo" "foo" --transcode=false cat mycred