Last change
on this file was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.3 KB
|
Rev | Line | |
---|
[444] | 1 | /* Reentrant version of rename system call. */ |
---|
| 2 | |
---|
| 3 | #include <reent.h> |
---|
| 4 | #include <stdio.h> |
---|
| 5 | #include <unistd.h> |
---|
| 6 | #include <sys/stat.h> |
---|
| 7 | #include <_syslist.h> |
---|
| 8 | |
---|
| 9 | /* Some targets provides their own versions of these functions. Those |
---|
| 10 | targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
---|
| 11 | |
---|
| 12 | #ifdef _REENT_ONLY |
---|
| 13 | #ifndef REENTRANT_SYSCALLS_PROVIDED |
---|
| 14 | #define REENTRANT_SYSCALLS_PROVIDED |
---|
| 15 | #endif |
---|
| 16 | #endif |
---|
| 17 | |
---|
| 18 | #ifndef REENTRANT_SYSCALLS_PROVIDED |
---|
| 19 | |
---|
| 20 | /* We use the errno variable used by the system dependent layer. */ |
---|
| 21 | #undef errno |
---|
| 22 | extern int errno; |
---|
| 23 | |
---|
| 24 | /* |
---|
| 25 | FUNCTION |
---|
| 26 | <<_rename_r>>---Reentrant version of rename |
---|
| 27 | |
---|
| 28 | INDEX |
---|
| 29 | _rename_r |
---|
| 30 | |
---|
| 31 | SYNOPSIS |
---|
| 32 | #include <reent.h> |
---|
| 33 | int _rename_r(struct _reent *<[ptr]>, |
---|
| 34 | const char *<[old]>, const char *<[new]>); |
---|
| 35 | |
---|
| 36 | DESCRIPTION |
---|
| 37 | This is a reentrant version of <<rename>>. It |
---|
| 38 | takes a pointer to the global data block, which holds |
---|
| 39 | <<errno>>. |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | int |
---|
| 43 | _rename_r (struct _reent *ptr, |
---|
| 44 | const char *old, |
---|
| 45 | const char *new) |
---|
| 46 | { |
---|
| 47 | int ret = 0; |
---|
| 48 | |
---|
| 49 | #ifdef HAVE_RENAME |
---|
| 50 | errno = 0; |
---|
| 51 | if ((ret = _rename (old, new)) == -1 && errno != 0) |
---|
| 52 | ptr->_errno = errno; |
---|
| 53 | #else |
---|
| 54 | if (_link_r (ptr, old, new) == -1) |
---|
| 55 | return -1; |
---|
| 56 | |
---|
| 57 | if (_unlink_r (ptr, old) == -1) |
---|
| 58 | { |
---|
| 59 | /* ??? Should we unlink new? (rhetorical question) */ |
---|
| 60 | return -1; |
---|
| 61 | } |
---|
| 62 | #endif |
---|
| 63 | return ret; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
---|
Note: See
TracBrowser
for help on using the repository browser.