libcsupport: Accept NULL for zero-length entries

This commit is contained in:
Sebastian Huber
2013-12-17 10:59:13 +01:00
parent 56bea4339f
commit c1d8ee4cdc
4 changed files with 31 additions and 23 deletions

View File

@@ -887,7 +887,7 @@ static inline ssize_t rtems_libio_iovec_eval(
total += ( ssize_t ) len; total += ( ssize_t ) len;
if ( iov[ v ].iov_base == NULL ) { if ( iov[ v ].iov_base == NULL && len != 0 ) {
rtems_set_errno_and_return_minus_one( EINVAL ); rtems_set_errno_and_return_minus_one( EINVAL );
} }
} }

View File

@@ -41,10 +41,13 @@ ssize_t rtems_filesystem_default_readv(
total = 0; total = 0;
for ( v = 0 ; v < iovcnt ; ++v ) { for ( v = 0 ; v < iovcnt ; ++v ) {
size_t len = iov[ v ].iov_len;
if ( len > 0 ) {
ssize_t bytes = ( *iop->pathinfo.handlers->read_h )( ssize_t bytes = ( *iop->pathinfo.handlers->read_h )(
iop, iop,
iov[ v ].iov_base, iov[ v ].iov_base,
iov[ v ].iov_len len
); );
if ( bytes < 0 ) if ( bytes < 0 )
@@ -52,9 +55,10 @@ ssize_t rtems_filesystem_default_readv(
total += bytes; total += bytes;
if ( bytes != iov[ v ].iov_len ) if ( bytes != ( ssize_t ) len )
break; break;
} }
}
return total; return total;
} }

View File

@@ -41,10 +41,13 @@ ssize_t rtems_filesystem_default_writev(
total = 0; total = 0;
for ( v = 0 ; v < iovcnt ; ++v ) { for ( v = 0 ; v < iovcnt ; ++v ) {
size_t len = iov[ v ].iov_len;
if ( len > 0 ) {
ssize_t bytes = ( *iop->pathinfo.handlers->write_h )( ssize_t bytes = ( *iop->pathinfo.handlers->write_h )(
iop, iop,
iov[ v ].iov_base, iov[ v ].iov_base,
iov[ v ].iov_len len
); );
if ( bytes < 0 ) if ( bytes < 0 )
@@ -52,9 +55,10 @@ ssize_t rtems_filesystem_default_writev(
total += bytes; total += bytes;
if ( bytes != iov[ v ].iov_len ) if ( bytes != ( ssize_t ) len )
break; break;
} }
}
return total; return total;
} }

View File

@@ -361,7 +361,7 @@ int doErrorTest(void)
/* writev -- all zero length buffers */ /* writev -- all zero length buffers */
vec[0].iov_base = vec; vec[0].iov_base = vec;
vec[0].iov_len = 0; vec[0].iov_len = 0;
vec[1].iov_base = vec; vec[1].iov_base = NULL;
vec[1].iov_len = 0; vec[1].iov_len = 0;
puts("writev iov_len works with no effect -- OK"); puts("writev iov_len works with no effect -- OK");
rc = writev(fd, vec, 2); rc = writev(fd, vec, 2);
@@ -374,7 +374,7 @@ int doErrorTest(void)
/* readv -- all zero length buffers */ /* readv -- all zero length buffers */
vec[0].iov_base = vec; vec[0].iov_base = vec;
vec[0].iov_len = 0; vec[0].iov_len = 0;
vec[1].iov_base = vec; vec[1].iov_base = NULL;
vec[1].iov_len = 0; vec[1].iov_len = 0;
puts("readv iov_len works with no effect -- OK"); puts("readv iov_len works with no effect -- OK");
rc = readv(fd, vec, 2); rc = readv(fd, vec, 2);