2007-09-19 03:32:43 +08:00
|
|
|
/* Reentrant version of rename system call. */
|
|
|
|
|
|
|
|
#include <reent.h>
|
2012-08-08 19:04:18 +08:00
|
|
|
#include <stdio.h>
|
2007-09-19 03:32:43 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <_syslist.h>
|
|
|
|
|
|
|
|
/* Some targets provides their own versions of these functions. Those
|
|
|
|
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
|
|
|
|
|
|
|
|
#ifdef _REENT_ONLY
|
|
|
|
#ifndef REENTRANT_SYSCALLS_PROVIDED
|
|
|
|
#define REENTRANT_SYSCALLS_PROVIDED
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef REENTRANT_SYSCALLS_PROVIDED
|
|
|
|
|
|
|
|
/* We use the errno variable used by the system dependent layer. */
|
|
|
|
#undef errno
|
|
|
|
extern int errno;
|
|
|
|
|
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<_rename_r>>---Reentrant version of rename
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
_rename_r
|
|
|
|
|
2017-11-30 15:41:14 +08:00
|
|
|
SYNOPSIS
|
2007-09-19 03:32:43 +08:00
|
|
|
#include <reent.h>
|
|
|
|
int _rename_r(struct _reent *<[ptr]>,
|
2008-11-25 05:27:33 +08:00
|
|
|
const char *<[old]>, const char *<[new]>);
|
2007-09-19 03:32:43 +08:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This is a reentrant version of <<rename>>. It
|
|
|
|
takes a pointer to the global data block, which holds
|
|
|
|
<<errno>>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
_DEFUN (_rename_r, (ptr, old, new),
|
2017-12-04 09:31:41 +08:00
|
|
|
struct _reent *ptr,
|
|
|
|
_CONST char *old,
|
2007-09-19 03:32:43 +08:00
|
|
|
_CONST char *new)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
#ifdef HAVE_RENAME
|
|
|
|
errno = 0;
|
|
|
|
if ((ret = _rename (old, new)) == -1 && errno != 0)
|
|
|
|
ptr->_errno = errno;
|
|
|
|
#else
|
|
|
|
if (_link_r (ptr, old, new) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (_unlink_r (ptr, old) == -1)
|
|
|
|
{
|
|
|
|
/* ??? Should we unlink new? (rhetorical question) */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
|