]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /*\r |
2 | * Copyright (c) 1999, 2000\r | |
3 | * Intel Corporation.\r | |
4 | * All rights reserved.\r | |
5 | *\r | |
6 | * Redistribution and use in source and binary forms, with or without modification,\r | |
7 | * are permitted provided that the following conditions are met:\r | |
8 | *\r | |
9 | * 1. Redistributions of source code must retain the above copyright notice,\r | |
10 | * this list of conditions and the following disclaimer.\r | |
11 | *\r | |
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,\r | |
13 | * this list of conditions and the following disclaimer in the documentation\r | |
14 | * and/or other materials provided with the distribution.\r | |
15 | *\r | |
16 | * 3. All advertising materials mentioning features or use of this software must\r | |
17 | * display the following acknowledgement:\r | |
18 | *\r | |
19 | * This product includes software developed by Intel Corporation and its\r | |
20 | * contributors.\r | |
21 | *\r | |
22 | * 4. Neither the name of Intel Corporation or its contributors may be used to\r | |
23 | * endorse or promote products derived from this software without specific\r | |
24 | * prior written permission.\r | |
25 | *\r | |
26 | * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS'' AND\r | |
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r | |
28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r | |
29 | * DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR\r | |
30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r | |
31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r | |
32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r | |
33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r | |
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r | |
35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r | |
36 | *\r | |
37 | */\r | |
38 | \r | |
39 | /*++\r | |
40 | \r | |
41 | Module Name:\r | |
42 | \r | |
43 | writev.c\r | |
44 | \r | |
45 | Abstract:\r | |
46 | \r | |
47 | Functions implementing the standard "writev" system call interface\r | |
48 | \r | |
49 | \r | |
50 | Revision History\r | |
51 | \r | |
52 | --*/\r | |
53 | #include <LibConfig.h>\r | |
54 | \r | |
55 | #ifdef foo\r | |
56 | #include <efi_interface.h>\r | |
57 | #include <unistd.h>\r | |
58 | #include <fcntl.h>\r | |
59 | #define KERNEL\r | |
60 | #include <errno.h>\r | |
61 | #undef KERNEL\r | |
62 | #include "./filedesc.h"\r | |
63 | \r | |
64 | #include <libc_debug.h>\r | |
65 | #include <assert.h>\r | |
66 | #endif\r | |
67 | \r | |
68 | #include <stdlib.h>\r | |
69 | #include <unistd.h>\r | |
70 | #include <sys/uio.h>\r | |
71 | #include <string.h>\r | |
72 | #ifndef KERNEL\r | |
73 | #define KERNEL\r | |
74 | #include <errno.h>\r | |
75 | #undef KERNEL\r | |
76 | #else\r | |
77 | #include <errno.h>\r | |
78 | #endif\r | |
79 | \r | |
80 | //\r | |
81 | // Name:\r | |
82 | // writev\r | |
83 | //\r | |
84 | // Description:\r | |
85 | // BSD writev interface for libc\r | |
86 | //\r | |
87 | // Arguments:\r | |
88 | // File Descriptor (index into file descriptor table)\r | |
89 | // iovec pointer\r | |
90 | // size of iovec array\r | |
91 | //\r | |
92 | // Returns:\r | |
93 | // number of bytes written\r | |
94 | //\r | |
95 | \r | |
96 | ssize_t\r | |
97 | writev(\r | |
98 | int fd,\r | |
99 | const struct iovec *iov,\r | |
100 | int iovcnt\r | |
101 | )\r | |
102 | {\r | |
103 | const struct iovec *pVecTmp;\r | |
104 | char *pBuf, *pBufTmp;\r | |
105 | size_t TotalBytes, i, ret;\r | |
106 | \r | |
107 | //\r | |
108 | // See how much memory we'll need\r | |
109 | //\r | |
110 | \r | |
111 | for (i = 0, TotalBytes = 0, pVecTmp = iov; i < (size_t)iovcnt; i++, pVecTmp++) {\r | |
112 | TotalBytes += pVecTmp->iov_len;\r | |
113 | }\r | |
114 | \r | |
115 | //\r | |
116 | // Allocate a contiguous buffer\r | |
117 | //\r | |
118 | \r | |
119 | pBuf = (char*)malloc (TotalBytes);\r | |
120 | if (pBuf == NULL) {\r | |
121 | errno = ENOMEM;\r | |
122 | return -1;\r | |
123 | }\r | |
124 | \r | |
125 | //\r | |
126 | // Copy vectors to the buffer\r | |
127 | //\r | |
128 | \r | |
129 | for (pBufTmp = pBuf; iovcnt; iovcnt--) {\r | |
130 | bcopy(iov->iov_base, pBuf, iov->iov_len);\r | |
131 | pBuf += iov->iov_len;\r | |
132 | iov++;\r | |
133 | }\r | |
134 | \r | |
135 | //\r | |
136 | // Use standard write(2) then free buffer\r | |
137 | //\r | |
138 | \r | |
139 | ret = write (fd, pBuf, TotalBytes);\r | |
140 | free (pBuf);\r | |
141 | \r | |
142 | return (ret);\r | |
143 | }\r |