Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / tools / testing / selftests / kselftest / prefix.pl
1 #!/usr/bin/perl
2 # SPDX-License-Identifier: GPL-2.0
3 # Prefix all lines with "# ", unbuffered. Command being piped in may need
4 # to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
5 use strict;
6
7 binmode STDIN;
8 binmode STDOUT;
9
10 STDOUT->autoflush(1);
11
12 my $needed = 1;
13 while (1) {
14         my $char;
15         my $bytes = sysread(STDIN, $char, 1);
16         exit 0 if ($bytes == 0);
17         if ($needed) {
18                 print "# ";
19                 $needed = 0;
20         }
21         print $char;
22         $needed = 1 if ($char eq "\n");
23 }