xref: /haiku/src/system/libroot/posix/unistd/read.c (revision a6e73cb9e8addfe832c064bfcb68067f1c2fa3eb)
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-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
8  * Distributed under the terms of the MIT License.
9  */
10 
11 
12 #include <unistd.h>
13 
14 #include <errno.h>
15 #include <pthread.h>
16 
17 #include <syscall_utils.h>
18 
19 #include <syscalls.h>
20 
21 
22 ssize_t
23 read(int fd, void* buffer, size_t bufferSize)
24 {
25 	ssize_t status = _kern_read(fd, -1, buffer, bufferSize);
26 
27 	RETURN_AND_SET_ERRNO_TEST_CANCEL(status);
28 }
29 
30 
31 ssize_t
32 read_pos(int fd, off_t pos, void* buffer, size_t bufferSize)
33 {
34 	if (pos < 0)
35 		RETURN_AND_SET_ERRNO_TEST_CANCEL(B_BAD_VALUE);
36 
37 	RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_read(fd, pos, buffer, bufferSize));
38 }
39 
40 
41 ssize_t
42 pread(int fd, void* buffer, size_t bufferSize, off_t pos)
43 {
44 	if (pos < 0)
45 		RETURN_AND_SET_ERRNO_TEST_CANCEL(B_BAD_VALUE);
46 
47 	RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_read(fd, pos, buffer, bufferSize));
48 }
49