summaryrefslogtreecommitdiff
path: root/tests/test-pread.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-11-25 18:26:35 +0100
committerJim Meyering <meyering@redhat.com>2009-11-25 18:26:35 +0100
commit1baf5e2a66516cbc706eeb23f2451862a7ab0f89 (patch)
tree6eaeda22874913377fa996aae1bce660ebfe0db3 /tests/test-pread.c
parent23cd74133c81b80d335c701848b71d85a53402c6 (diff)
downloadgnulib-1baf5e2a66516cbc706eeb23f2451862a7ab0f89.tar.gz
test-pread: cover failure with ESPIPE and EINVAL
* tests/test-pread.c (main): Test for failure, too. * tests/test-pread.sh: Invoke with stdin on a pipe. Suggested by Eric Blake.
Diffstat (limited to 'tests/test-pread.c')
-rw-r--r--tests/test-pread.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test-pread.c b/tests/test-pread.c
index cf4179f32f..fd5db8e8a1 100644
--- a/tests/test-pread.c
+++ b/tests/test-pread.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
+#include <errno.h>
#define ASSERT(expr) \
do \
@@ -72,7 +73,22 @@ main (void)
}
}
+ {
+ /* Invalid offset must evoke failure with EINVAL. */
+ char byte;
+ ASSERT (pread (fd, &byte, 1, (off_t) -1) == -1);
+ ASSERT (errno == EINVAL);
+ }
+
ASSERT (close (fd) == 0);
+ {
+ char byte;
+ /* Trying to operate on a pipe must evoke failure with ESPIPE.
+ This assumes that stdin is a pipe, and hence not seekable. */
+ ASSERT (pread (STDIN_FILENO, &byte, 1, 1) == -1);
+ ASSERT (errno == ESPIPE);
+ }
+
return 0;
}