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 #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; 38 if (pos < 0) { 39 errno = B_BAD_VALUE; 40 return -1; 41 } 42 status = _kern_read(fd, pos, buffer, bufferSize); 43 44 RETURN_AND_SET_ERRNO(status); 45 } 46 47 48 ssize_t 49 pread(int fd, void* buffer, size_t bufferSize, off_t pos) 50 { 51 ssize_t status; 52 if (pos < 0) { 53 errno = B_BAD_VALUE; 54 return -1; 55 } 56 status = _kern_read(fd, pos, buffer, bufferSize); 57 58 RETURN_AND_SET_ERRNO(status); 59 } 60