2 # Ensure we handle i/o errors correctly in csplit
4 # Copyright (C) 2015-2016 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 <http://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
23 if ! test -w /dev
/full ||
! test -c /dev
/full
; then
24 skip_
'/dev/full is required'
27 # Ensure error messages are in English
31 # Replace fwrite and ferror, always returning an error
32 cat > k.c
<<'EOF' || framework_failure_
37 #undef fwrite_unlocked
40 fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream)
42 fclose (fopen ("preloaded","w")); /* marker for preloaded interception */
48 fwrite_unlocked (const void *ptr, size_t size, size_t nitems, FILE *stream)
50 return fwrite (ptr, size, nitems, stream);
54 # Get the wording of the OS-dependent ENOSPC message
55 returns_
1 seq 1 >/dev
/full
2>msgt || framework_failure_
56 sed 's/seq: write error: //' msgt
> msg || framework_failure_
58 # Create the expected error message
59 { printf "%s" "csplit: write error for 'xx01': " ; cat msg
; } > exp \
62 # compile/link the interception shared library:
63 gcc_shared_ k.c k.so \
64 || skip_
'failed to build forced-fwrite-failure shared library'
66 # Split the input, and force fwrite() failure -
67 # the 'csplit' command should fail with exit code 1
68 # (checked with 'returns_ 1 ... || fail=1')
70 | LD_PRELOAD
=$LD_PRELOAD:.
/k.so returns_
1 csplit
- 1 4 2>out \
73 test -e preloaded || skip_
'LD_PRELOAD interception failed'
75 # Ensure we got the expected error message
76 compare exp out || fail
=1