View | Details | Raw Unified | Return to bug 222671
Collapse All | Expand All

(-)usr.bin/tail/reverse.c (-2 / +5 lines)
Lines 257-266 Link Here
257
			if ((*p == '\n') || start) {
257
			if ((*p == '\n') || start) {
258
				struct bfelem *tr;
258
				struct bfelem *tr;
259
259
260
				if (start && llen)
260
				if (llen && start && *p != '\n')
261
					WR(p, llen + 1);
261
					WR(p, llen + 1);
262
				else if (llen)
262
				else if (llen) {
263
					WR(p + 1, llen);
263
					WR(p + 1, llen);
264
					if (start && *p == '\n')
265
						WR(p, 1);
266
				}
264
				tr = TAILQ_NEXT(tl, entries);
267
				tr = TAILQ_NEXT(tl, entries);
265
				llen = 0;
268
				llen = 0;
266
				if (tr != NULL) {
269
				if (tr != NULL) {
(-)usr.bin/tail/tests/tail_test.sh (+44 lines)
Lines 83-88 Link Here
83
	atf_check cmp expectfile outpipe
83
	atf_check cmp expectfile outpipe
84
}
84
}
85
85
86
# Regression test for PR 222671
87
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222671
88
atf_test_case pipe_leading_newline_r
89
pipe_leading_newline_r_head()
90
{
91
	atf_set "descr" "Reverse a pipe whose first character is a newline"
92
}
93
pipe_leading_newline_r_body()
94
{
95
	cat > expectfile << HERE
96
3
97
2
98
1
99
100
HERE
101
	printf '\n1\n2\n3\n' | tail -r > outfile
102
	printf '\n1\n2\n3\n' | tail -r > outpipe
103
	atf_check cmp expectfile outfile
104
	atf_check cmp expectfile outpipe
105
}
106
86
atf_test_case file_rc28
107
atf_test_case file_rc28
87
file_rc28_head()
108
file_rc28_head()
88
{
109
{
Lines 105-110 Link Here
105
	atf_check cmp expectfile outpipe
126
	atf_check cmp expectfile outpipe
106
}
127
}
107
128
129
atf_test_case file_rc28
130
file_rc28_head()
131
{
132
	atf_set "descr" "Reverse a file and display the last 28 characters"
133
}
134
file_rc28_body()
135
{
136
	cat > infile <<HERE
137
This is the first line
138
This is the second line
139
This is the third line
140
HERE
141
	cat > expectfile << HERE
142
This is the third line
143
line
144
HERE
145
	tail -rc28 infile > outfile
146
	tail -rc28 < infile > outpipe
147
	atf_check cmp expectfile outfile
148
	atf_check cmp expectfile outpipe
149
}
150
108
atf_test_case longfile_r
151
atf_test_case longfile_r
109
longfile_r_head()
152
longfile_r_head()
110
{
153
{
Lines 235-240 Link Here
235
	atf_add_test_case file_r
278
	atf_add_test_case file_r
236
	atf_add_test_case file_rc28
279
	atf_add_test_case file_rc28
237
	atf_add_test_case file_rn2
280
	atf_add_test_case file_rn2
281
	atf_add_test_case pipe_leading_newline_r
238
	# The longfile tests are designed to exercise behavior in r_buf(),
282
	# The longfile tests are designed to exercise behavior in r_buf(),
239
	# which operates on 128KB blocks
283
	# which operates on 128KB blocks
240
	atf_add_test_case longfile_r
284
	atf_add_test_case longfile_r

Return to bug 222671