2 # verify that od --endian works properly
4 # Copyright (C) 2014-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
27 # rev(1) is not generally available, so here's a simplistic
28 # implementation sufficient for our purposes.
31 printf '%s' "$line" |
sed "s/./&\\$NL/g" |
tac |
paste -s -d ''
35 in_swapped
() { printf '%s' "$in" |
sed "s/.\{$1\}/&\\$NL/g" |
rev |
tr -d '\n'; }
37 for e
in little big
; do
38 test $e = little
&& eo
=big || eo
=little
39 for s
in 1 2 4 8 16; do
41 od -t $t$s --endian=$e /dev
/null
> /dev
/null
2>&1 ||
continue
42 printf '%s' "$in" |
od -An -t $t$s --endian=$e > out1
43 in_swapped
"$s" |
od -An -t $t$s --endian=$eo > out2
44 compare out1 out2 || fail
=1