Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / reent / readr.c
blobb2ae300d32f6fe24380aa7697903026be8d69c31
1 /* Reentrant versions of read system call. */
3 #include <reent.h>
4 #include <unistd.h>
5 #include <_syslist.h>
7 /* Some targets provides their own versions of this functions. Those
8 targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
10 #ifdef _REENT_ONLY
11 #ifndef REENTRANT_SYSCALLS_PROVIDED
12 #define REENTRANT_SYSCALLS_PROVIDED
13 #endif
14 #endif
16 #ifndef REENTRANT_SYSCALLS_PROVIDED
18 /* We use the errno variable used by the system dependent layer. */
19 #undef errno
20 extern int errno;
23 FUNCTION
24 <<_read_r>>---Reentrant version of read
26 INDEX
27 _read_r
29 SYNOPSIS
30 #include <reent.h>
31 _ssize_t _read_r(struct _reent *<[ptr]>,
32 int <[fd]>, void *<[buf]>, size_t <[cnt]>);
34 DESCRIPTION
35 This is a reentrant version of <<read>>. It
36 takes a pointer to the global data block, which holds
37 <<errno>>.
40 _ssize_t
41 _read_r (struct _reent *ptr,
42 int fd,
43 void *buf,
44 size_t cnt)
46 _ssize_t ret;
48 errno = 0;
49 if ((ret = (_ssize_t)_read (fd, buf, cnt)) == -1 && errno != 0)
50 _REENT_ERRNO(ptr) = errno;
51 return ret;
54 #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */