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