xref: /haiku/src/system/libroot/posix/unistd/read.c (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 /*
2 ** Copyright 2001, Manuel J. Petit. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 
6 /*
7 ** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
8 ** Distributed under the terms of the OpenBeOS License.
9 */
10 
11 
12 #include <unistd.h>
13 #include <syscalls.h>
14 #include <errno.h>
15 
16 
17 #define RETURN_AND_SET_ERRNO(err) \
18 	if (err < 0) { \
19 		errno = err; \
20 		return -1; \
21 	} \
22 	return err;
23 
24 
25 ssize_t
26 read(int fd, void *buffer, size_t bufferSize)
27 {
28 	ssize_t status = _kern_read(fd, -1, buffer, bufferSize);
29 
30 	RETURN_AND_SET_ERRNO(status);
31 }
32 
33 
34 ssize_t
35 read_pos(int fd, off_t pos, void *buffer, size_t bufferSize)
36 {
37 	ssize_t status = _kern_read(fd, pos, buffer, bufferSize);
38 
39 	RETURN_AND_SET_ERRNO(status);
40 }
41 
42 
43 ssize_t
44 pread(int fd, void *buffer, size_t bufferSize, off_t pos)
45 {
46 	ssize_t status = _kern_read(fd, pos, buffer, bufferSize);
47 
48 	RETURN_AND_SET_ERRNO(status);
49 }
50 
51