xref: /haiku/src/system/libroot/posix/sys/uio.c (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
5 
6 
7 #include <syscalls.h>
8 
9 #include <sys/uio.h>
10 #include <errno.h>
11 
12 
13 #define RETURN_AND_SET_ERRNO(err) \
14 	if (err < 0) { \
15 		errno = err; \
16 		return -1; \
17 	} \
18 	return err;
19 
20 
21 ssize_t
22 readv(int fd, const struct iovec *vecs, size_t count)
23 {
24 	ssize_t bytes = _kern_readv(fd, -1, vecs, count);
25 
26 	RETURN_AND_SET_ERRNO(bytes);
27 }
28 
29 
30 ssize_t
31 readv_pos(int fd, off_t pos, const struct iovec *vecs, size_t count)
32 {
33 	ssize_t bytes;
34 	if (pos < 0) {
35 		errno = B_BAD_VALUE;
36 		return -1;
37 	}
38 	bytes = _kern_readv(fd, pos, vecs, count);
39 
40 	RETURN_AND_SET_ERRNO(bytes);
41 }
42 
43 
44 ssize_t
45 writev(int fd, const struct iovec *vecs, size_t count)
46 {
47 	ssize_t bytes = _kern_writev(fd, -1, vecs, count);
48 
49 	RETURN_AND_SET_ERRNO(bytes);
50 }
51 
52 
53 ssize_t
54 writev_pos(int fd, off_t pos, const struct iovec *vecs, size_t count)
55 {
56 	ssize_t bytes;
57 	if (pos < 0) {
58 		errno = B_BAD_VALUE;
59 		return -1;
60 	}
61 	bytes = _kern_writev(fd, pos, vecs, count);
62 
63 	RETURN_AND_SET_ERRNO(bytes);
64 }
65 
66