Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / reent / openr.c
blob824315438e85712192e94ad866c4bcc6e113efeb
1 /* Reentrant versions of open system call. */
3 #include <reent.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <_syslist.h>
8 /* Some targets provides their own versions of this functions. Those
9 targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
11 #ifdef _REENT_ONLY
12 #ifndef REENTRANT_SYSCALLS_PROVIDED
13 #define REENTRANT_SYSCALLS_PROVIDED
14 #endif
15 #endif
17 #ifndef REENTRANT_SYSCALLS_PROVIDED
19 /* We use the errno variable used by the system dependent layer. */
20 #undef errno
21 extern int errno;
24 FUNCTION
25 <<_open_r>>---Reentrant version of open
27 INDEX
28 _open_r
30 SYNOPSIS
31 #include <reent.h>
32 int _open_r(struct _reent *<[ptr]>,
33 const char *<[file]>, int <[flags]>, int <[mode]>);
35 DESCRIPTION
36 This is a reentrant version of <<open>>. It
37 takes a pointer to the global data block, which holds
38 <<errno>>.
41 int
42 _open_r (struct _reent *ptr,
43 const char *file,
44 int flags,
45 int mode)
47 int ret;
49 errno = 0;
50 if ((ret = _open (file, flags, mode)) == -1 && errno != 0)
51 _REENT_ERRNO(ptr) = errno;
52 return ret;
56 #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */