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