]> git.sesse.net Git - vlc/blob - include/input_iovec.h
The win32 interface is preparing for the internationalization.
[vlc] / include / input_iovec.h
1 /*****************************************************************************
2  * input_iovec.h: iovec structure
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *          Jon Lech Johansen <jon-vl@nanocrew.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * iovec structure: vectored data entry
26  *****************************************************************************/
27 struct iovec
28 {
29     void *iov_base;     /* Pointer to data. */
30     size_t iov_len;     /* Length of data.  */
31 };
32
33 /*****************************************************************************
34  * readv_*: readv() replacements for iovec-impaired C libraries
35  *****************************************************************************/
36 #if defined( WIN32 )
37 static inline int readv( int i_fd, struct iovec *p_iovec, int i_count )
38 {
39     int i_index, i_len, i_total = 0;
40     unsigned char *p_base;
41     int i_bytes;
42
43     for( i_index = i_count; i_index; i_index-- )
44     {
45
46         i_len  = p_iovec->iov_len;
47         p_base = p_iovec->iov_base;
48
49         /* Loop is unrolled one time to spare the (i_bytes <= 0) test */
50
51         if( i_len > 0 )
52         {
53             i_bytes = read( i_fd, p_base, i_len );
54
55             if( i_bytes < 0 )
56             {
57                 /* One of the reads failed, too bad.
58                    We won't even bother returning the reads that went ok,
59                    and as in the posix spec the file postition is left
60                    unspecified after a failure */
61                 return -1;
62             }
63
64             i_total += i_bytes;
65
66             if( i_bytes != i_len )
67             {
68                 /* we reached the end of the file or a signal interrupted
69                    the read */
70                 return i_total;
71             }
72         }
73
74         p_iovec++;
75     }
76
77     return i_total;
78 }
79 #endif /* WIN32 */