* Fix fread() issue with standard input reading.

This commit is contained in:
Sam Hocevar
2007-01-06 15:54:14 +00:00
committed by sam
parent e381e7bb86
commit 2029e77e18
2 changed files with 12 additions and 5 deletions

View File

@@ -179,8 +179,12 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
if(ret >= 0)
{
/* XXX: the number of bytes read is not ret * size, because
* a partial read may have advanced the stream pointer */
* a partial read may have advanced the stream pointer. However,
* when reading from a pipe ftell() will return 0, and ret * size
* is then better than nothing. */
long int newpos = ftell(stream);
if(newpos <= 0)
newpos = ret * size;
if(newpos != pos)
{
_zz_fuzz(fd, ptr, newpos - pos);

View File

@@ -18,7 +18,7 @@ check()
ZZOPTS="$1"
CMD="$2"
ALIAS="$3"
echo -n " $(echo "$ALIAS: " | cut -b1-15)"
echo -n " $(echo "$ALIAS .............." | cut -b1-15) "
NEWMD5="$(eval "$ZZUF $ZZOPTS $CMD" 2>/dev/null | md5sum | cut -b1-32)"
if [ -z "$MD5" ]; then
MD5="$NEWMD5"
@@ -69,15 +69,18 @@ for r in 0.000000 0.00001 0.0001 0.001 0.01 0.1 1.0 10.0; do
OK=1
MD5=""
check "$ZZOPTS" "cat $file" "cat"
check "$ZZOPTS" "-i cat < $file" "cat stdin"
check "$ZZOPTS" "-i cat < $file" "|cat"
case $file in
*text*)
# We don't include grep or sed when the input is not text, because
# they put a newline at the end of their input if it was not there
# initially. (Linux sed doesn't, but OS X sed does.)
check "$ZZOPTS" "grep -- -a '' $file" "grep -a ''"
check "$ZZOPTS" "-- sed -e n $file" "sed -e n"
#check "$ZZOPTS" "-- cut -b1- $file" "cut -b1-"
check "$ZZOPTS" "-i grep -- -a '' < $file" "|grep -a ''"
check "$ZZOPTS" "sed -- -e n $file" "sed -e n"
check "$ZZOPTS" "-i sed -- -e n < $file" "|sed -e n"
#check "$ZZOPTS" "cut -- -b1- $file" "cut -b1-"
#check "$ZZOPTS" "-i cut -- -b1- < $file" "|cut -b1-"
;;
esac
check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"