]> git.sesse.net Git - vlc/blobdiff - include/input_iovec.h
* ./configure.in: checking for the header should be enough in most cases
[vlc] / include / input_iovec.h
index fa086e3eac90b26156861d54508ae2fe06fd7d31..b2cd4c2e71a79d907b2d4195538f81c2d5fa2f04 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * input_iovec.h: iovec structure and readv() replacement
+ * input_iovec.h: iovec structure
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
  *
@@ -30,53 +30,44 @@ struct iovec
     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;
             }
         }
 
@@ -85,5 +76,4 @@ static __inline int readv( int i_fd, struct iovec *p_iovec, int i_count )
 
     return i_total;
 }
-
-#endif
+#endif /* WIN32 */