xref: /haiku/src/system/libroot/posix/sys/uio.c (revision 778611c7e6a61b8ba072212756ce53eda826360a)
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 #include <errno_private.h>
13 
14 
15 #define RETURN_AND_SET_ERRNO(err) \
16 	if (err < 0) { \
17 		__set_errno(err); \
18 		return -1; \
19 	} \
20 	return err;
21 
22 
23 ssize_t
24 readv(int fd, const struct iovec *vecs, size_t count)
25 {
26 	ssize_t bytes = _kern_readv(fd, -1, vecs, count);
27 
28 	RETURN_AND_SET_ERRNO(bytes);
29 }
30 
31 
32 ssize_t
33 readv_pos(int fd, off_t pos, const struct iovec *vecs, size_t count)
34 {
35 	ssize_t bytes;
36 	if (pos < 0) {
37 		__set_errno(B_BAD_VALUE);
38 		return -1;
39 	}
40 	bytes = _kern_readv(fd, pos, vecs, count);
41 
42 	RETURN_AND_SET_ERRNO(bytes);
43 }
44 
45 
46 ssize_t
47 writev(int fd, const struct iovec *vecs, size_t count)
48 {
49 	ssize_t bytes = _kern_writev(fd, -1, vecs, count);
50 
51 	RETURN_AND_SET_ERRNO(bytes);
52 }
53 
54 
55 ssize_t
56 writev_pos(int fd, off_t pos, const struct iovec *vecs, size_t count)
57 {
58 	ssize_t bytes;
59 	if (pos < 0) {
60 		__set_errno(B_BAD_VALUE);
61 		return -1;
62 	}
63 	bytes = _kern_writev(fd, pos, vecs, count);
64 
65 	RETURN_AND_SET_ERRNO(bytes);
66 }
67 
68