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