Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / reent / renamer.c
blob7e1e111a8d20323821dd96b1b1ef462b838b11ea
1 /* Reentrant version of rename system call. */
3 #include <reent.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <sys/stat.h>
7 #include <_syslist.h>
9 /* Some targets provides their own versions of these functions. Those
10 targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
12 #ifdef _REENT_ONLY
13 #ifndef REENTRANT_SYSCALLS_PROVIDED
14 #define REENTRANT_SYSCALLS_PROVIDED
15 #endif
16 #endif
18 #ifndef REENTRANT_SYSCALLS_PROVIDED
20 /* We use the errno variable used by the system dependent layer. */
21 #undef errno
22 extern int errno;
25 FUNCTION
26 <<_rename_r>>---Reentrant version of rename
28 INDEX
29 _rename_r
31 SYNOPSIS
32 #include <reent.h>
33 int _rename_r(struct _reent *<[ptr]>,
34 const char *<[old]>, const char *<[new]>);
36 DESCRIPTION
37 This is a reentrant version of <<rename>>. It
38 takes a pointer to the global data block, which holds
39 <<errno>>.
42 int
43 _rename_r (struct _reent *ptr,
44 const char *old,
45 const char *new)
47 int ret = 0;
49 #ifdef HAVE_RENAME
50 errno = 0;
51 if ((ret = _rename (old, new)) == -1 && errno != 0)
52 _REENT_ERRNO(ptr) = errno;
53 #else
54 if (_link_r (ptr, old, new) == -1)
55 return -1;
57 if (_unlink_r (ptr, old) == -1)
59 /* ??? Should we unlink new? (rhetorical question) */
60 return -1;
62 #endif
63 return ret;
66 #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */