Fix return value of fdio fread(3) and fwrite(3).

Previously fread and fwrite for file descriptors would return the number of
bytes read/written rather than the number of elements read/written. This
breaks the C standard and broke various third party programs such as
readelf from binutils.
This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-03 10:19:09 +02:00
parent b4192c10e9
commit 29f5cd2335
1 changed files with 6 additions and 5 deletions

View File

@ -52,11 +52,11 @@ static size_t fdio_read(void* ptr, size_t size, size_t nmemb, void* user)
while ( sofar < total )
{
ssize_t numbytes = read(fdio->fd, buf + sofar, total - sofar);
if ( numbytes < 0 ) { fdio->flags |= FDIO_ERROR; return sofar; }
if ( numbytes == 0 ) { fdio->flags |= FDIO_EOF; return sofar; }
if ( numbytes < 0 ) { fdio->flags |= FDIO_ERROR; break; }
if ( numbytes == 0 ) { fdio->flags |= FDIO_EOF; break; }
sofar += numbytes;
}
return sofar;
return sofar / size;
}
static size_t fdio_write(const void* ptr, size_t size, size_t nmemb, void* user)
@ -69,10 +69,11 @@ static size_t fdio_write(const void* ptr, size_t size, size_t nmemb, void* user)
while ( sofar < total )
{
ssize_t numbytes = write(fdio->fd, buf + sofar, total - sofar);
if ( numbytes < 0 ) { fdio->flags |= FDIO_ERROR; return sofar; }
if ( numbytes < 0 ) { fdio->flags |= FDIO_ERROR; break; }
if ( numbytes == 0 ) { fdio->flags |= FDIO_EOF; break; }
sofar += numbytes;
}
return sofar;
return sofar / size;
}
static int fdio_seek(void* user, off_t offset, int whence)