/*****************************************************************************
- * input_iovec.h: iovec structure and readv() replacement
+ * input_iovec.h: iovec structure
*****************************************************************************
* Copyright (C) 2001 VideoLAN
*
size_t iov_len; /* Length of data. */
};
-#if defined( WIN32 )
/*****************************************************************************
- * readv: readv() replacement for iovec-impaired C libraries
+ * readv_*: readv() replacements for iovec-impaired C libraries
*****************************************************************************/
-static __inline int readv( int i_fd, struct iovec *p_iovec, int i_count )
+#if defined( WIN32 )
+static inline int readv( int i_fd, struct iovec *p_iovec, int i_count )
{
int i_index, i_len, i_total = 0;
- char *p_base;
+ unsigned char *p_base;
+ int i_bytes;
for( i_index = i_count; i_index; i_index-- )
{
- register signed int i_bytes;
i_len = p_iovec->iov_len;
p_base = p_iovec->iov_base;
- /* Loop is unrolled one time to spare the (i_bytes < 0) test */
+ /* Loop is unrolled one time to spare the (i_bytes <= 0) test */
+
if( i_len > 0 )
{
i_bytes = read( i_fd, p_base, i_len );
- if( ( i_total == 0 ) && ( i_bytes < 0 ) )
+ if( i_bytes < 0 )
{
+ /* One of the reads failed, too bad.
+ We won't even bother returning the reads that went ok,
+ and as in the posix spec the file postition is left
+ unspecified after a failure */
return -1;
}
- if( i_bytes <= 0 )
- {
- return i_total;
- }
-
- i_len -= i_bytes;
i_total += i_bytes;
- p_base += i_bytes;
- while( i_len > 0 )
+ if( i_bytes != i_len )
{
- i_bytes = read( i_fd, p_base, i_len );
-
- if( i_bytes <= 0 )
- {
- return i_total;
- }
-
- i_len -= i_bytes;
- i_total += i_bytes;
- p_base += i_bytes;
+ /* we reached the end of the file or a signal interrupted
+ the read */
+ return i_total;
}
}
return i_total;
}
-
-#endif
+#endif /* WIN32 */