From 535a9fe5122808161398345f5ab317bd1ef6bde8 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 15 Aug 2007 22:44:45 +0200 Subject: od --skip (-j) works even on files in /proc, when the kernel lies * src/od.c (skip): Don't let kernel misinformation (nonempty files in /proc with stat.st_size == 0) make "od -j N" misbehave. Patch by Paul Eggert. * NEWS: Document this work-around. * tests/misc/od-zero-len: New file, test for the above. --- tests/misc/od-zero-len | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 tests/misc/od-zero-len (limited to 'tests') diff --git a/tests/misc/od-zero-len b/tests/misc/od-zero-len new file mode 100755 index 000000000..42008ce8e --- /dev/null +++ b/tests/misc/od-zero-len @@ -0,0 +1,53 @@ +#!/bin/sh +# ensure that od -j doesn't improperly fseek across a nonempty file in /proc + +# Copyright (C) 2007 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 . + +if test "$VERBOSE" = yes; then + set -x + od --version +fi + +pwd=`pwd` +t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ +trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +framework_failure=0 +mkdir -p $tmp || framework_failure=1 +cd $tmp || framework_failure=1 +printf e > f2 || framework_failure=1 + +if test $framework_failure = 1; then + echo "$0: failure in testing framework" 1>&2 + (exit 1); exit 1 +fi + +# Use a file in /proc whose size is not likely to +# change between the wc and od invocations. +f=/proc/version +test -r $f || f=empty + +fail=0 + +n=`wc -c < $f` || fail=1 +od -An -c -j $n $f f2 > out || fail=1 +echo ' e' > exp || fail=1 + +cmp out exp || fail=1 +test $fail = 1 && diff out exp 2> /dev/null + +(exit $fail); exit $fail -- cgit v1.2.3-54-g00ecf