Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / reent / sbrkr.c
blobec948fe6bf0ef07050b13c9a7c383f4185fee4a3
1 /* Reentrant version of sbrk system call. */
3 #include <reent.h>
4 #include <unistd.h>
5 #include <_syslist.h>
7 /* Some targets provides their own versions of these 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 #if defined (REENTRANT_SYSCALLS_PROVIDED)
18 int _dummy_sbrk_syscalls = 1;
20 #else
22 /* We use the errno variable used by the system dependent layer. */
23 #undef errno
24 extern int errno;
27 FUNCTION
28 <<_sbrk_r>>---Reentrant version of sbrk
30 INDEX
31 _sbrk_r
33 SYNOPSIS
34 #include <reent.h>
35 void *_sbrk_r(struct _reent *<[ptr]>, ptrdiff_t <[incr]>);
37 DESCRIPTION
38 This is a reentrant version of <<sbrk>>. It
39 takes a pointer to the global data block, which holds
40 <<errno>>.
43 void *
44 _sbrk_r (struct _reent *ptr,
45 ptrdiff_t incr)
47 char *ret;
48 void *_sbrk(ptrdiff_t);
50 errno = 0;
51 if ((ret = (char *)(_sbrk (incr))) == (void *) -1 && errno != 0)
52 _REENT_ERRNO(ptr) = errno;
53 return ret;
56 #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */