mariadb/bdb/os_win32/os_rename.c

78 lines
1.6 KiB
C
Raw Normal View History

2001-03-04 19:42:05 -05:00
/*-
* See the file LICENSE for redistribution information.
*
2002-10-30 15:57:05 +04:00
* Copyright (c) 1997-2002
2001-03-04 19:42:05 -05:00
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
2002-10-30 15:57:05 +04:00
static const char revid[] = "$Id: os_rename.c,v 1.12 2002/07/12 18:56:55 bostic Exp $";
2001-03-04 19:42:05 -05:00
#endif /* not lint */
#include "db_int.h"
/*
* __os_rename --
* Rename a file.
*/
int
2002-10-30 15:57:05 +04:00
__os_rename(dbenv, oldname, newname, flags)
2001-03-04 19:42:05 -05:00
DB_ENV *dbenv;
2002-10-30 15:57:05 +04:00
const char *oldname, *newname;
u_int32_t flags;
2001-03-04 19:42:05 -05:00
{
int ret;
2002-10-30 15:57:05 +04:00
char oldbuf[MAX_PATH], newbuf[MAX_PATH];
2001-03-04 19:42:05 -05:00
ret = 0;
2002-10-30 15:57:05 +04:00
if (DB_GLOBAL(j_rename) != NULL) {
if (DB_GLOBAL(j_rename)(oldname, newname) == -1)
2001-03-04 19:42:05 -05:00
ret = __os_get_errno();
2002-10-30 15:57:05 +04:00
goto done;
2001-03-04 19:42:05 -05:00
}
2002-10-30 15:57:05 +04:00
if (!MoveFile(oldname, newname))
ret = __os_win32_errno();
if (ret == EEXIST) {
ret = 0;
if (__os_is_winnt()) {
if (!MoveFileEx(
oldname, newname, MOVEFILE_REPLACE_EXISTING))
ret = __os_win32_errno();
} else {
/*
* There is no MoveFileEx for Win9x/Me, so we have to
* do the best we can.
*/
LPTSTR FilePath;
if (!GetFullPathName(oldname, sizeof(oldbuf), oldbuf,
&FilePath) ||
2003-03-01 12:43:09 +04:00
!GetFullPathName(newname, sizeof(newbuf), newbuf,
&FilePath)) {
2002-10-30 15:57:05 +04:00
ret = __os_win32_errno();
goto done;
}
/*
* If the old and new names differ only in case, we're
* done.
*/
if (strcasecmp(oldbuf, newbuf) == 0)
goto done;
(void)DeleteFile(newname);
if (!MoveFile(oldname, newname))
ret = __os_win32_errno();
}
2001-03-04 19:42:05 -05:00
}
2002-10-30 15:57:05 +04:00
done: if (ret != 0 && flags == 0)
__db_err(dbenv,
"Rename %s %s: %s", oldname, newname, strerror(ret));
2001-03-04 19:42:05 -05:00
return (ret);
}