[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] pread: new module
From: |
Jim Meyering |
Subject: |
Re: [PATCH 1/2] pread: new module |
Date: |
Wed, 25 Nov 2009 18:27:16 +0100 |
Eric Blake wrote:
> Jim Meyering <jim <at> meyering.net> writes:
>
>> + off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR);
>
>> +Depends-on:
>> +unistd
>> +
>
> Needs to depend on lseek, particularly since pread is replaced on mingw, and
> mingw has an lseek bug with non-seekable files (like pipes).
>
> Perhaps test-pread.sh should also check that pread fails with ESPIPE on a non-
> seekable fd? Also, the test should probably cover EINVAL for trying to read
> negative offsets.
Thanks again for all the suggestions.
>From 1baf5e2a66516cbc706eeb23f2451862a7ab0f89 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 25 Nov 2009 18:26:35 +0100
Subject: [PATCH] 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.
---
ChangeLog | 5 +++++
tests/test-pread.c | 16 ++++++++++++++++
tests/test-pread.sh | 2 +-
3 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2e5f9fb..2ec9906 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2009-11-25 Jim Meyering <address@hidden>
+ 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.
+
pread: improvement and fix
* modules/pread (Depends-on): Depend on lseek, for portability to
e.g., mingw. Suggested by Eric Blake.
diff --git a/tests/test-pread.c b/tests/test-pread.c
index cf4179f..fd5db8e 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;
}
diff --git a/tests/test-pread.sh b/tests/test-pread.sh
index 98971a4..5ab88eb 100755
--- a/tests/test-pread.sh
+++ b/tests/test-pread.sh
@@ -3,6 +3,6 @@
. $srcdir/init.sh --set-path=.
fail=0;
-test-pread || fail=1
+echo abc | test-pread || fail=1
Exit $fail
--
1.6.6.rc0.236.ge0b94
- [PATCH 1/2] pread: new module, Jim Meyering, 2009/11/25
- Re: [PATCH 1/2] pread: new module, Richard W.M. Jones, 2009/11/25
- Re: [PATCH 1/2] pread: new module, Eric Blake, 2009/11/25
- Re: [PATCH 1/2] pread: new module, Jim Meyering, 2009/11/25
- Re: [PATCH 1/2] pread: new module, Jim Meyering, 2009/11/25
- Re: [PATCH 1/2] pread: new module,
Jim Meyering <=
- Re: [PATCH 1/2] pread: new module, Bruno Haible, 2009/11/25
- Re: [PATCH 1/2] pread: new module, Eric Blake, 2009/11/26
- Re: [PATCH 1/2] pread: new module, Jim Meyering, 2009/11/26
- Re: [PATCH 1/2] pread: new module, Bruno Haible, 2009/11/26
- Re: [PATCH 1/2] pread: new module, Jim Meyering, 2009/11/26