source: trunk/third/rpm/db/os_win32/os_rename.c @ 19079

Revision 19079, 1.3 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r19078, which included commits to RCS files with non-trunk default branches.
Line 
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997-2002
5 *      Sleepycat Software.  All rights reserved.
6 */
7
8#include "db_config.h"
9
10#ifndef lint
11static const char revid[] = "Id: os_rename.c,v 1.12 2002/07/12 18:56:55 bostic Exp ";
12#endif /* not lint */
13
14#include "db_int.h"
15
16/*
17 * __os_rename --
18 *      Rename a file.
19 */
20int
21__os_rename(dbenv, oldname, newname, flags)
22        DB_ENV *dbenv;
23        const char *oldname, *newname;
24        u_int32_t flags;
25{
26        int ret;
27
28        ret = 0;
29        if (DB_GLOBAL(j_rename) != NULL) {
30                if (DB_GLOBAL(j_rename)(oldname, newname) == -1)
31                        ret = __os_get_errno();
32                goto done;
33        }
34
35        if (!MoveFile(oldname, newname))
36                ret = __os_win32_errno();
37
38        if (ret == EEXIST) {
39                ret = 0;
40                if (__os_is_winnt()) {
41                        if (!MoveFileEx(
42                            oldname, newname, MOVEFILE_REPLACE_EXISTING))
43                                ret = __os_win32_errno();
44                } else {
45                        /*
46                         * There is no MoveFileEx for Win9x/Me, so we have to
47                         * do the best we can.  Note that MoveFile returns 1
48                         * if the names refer to the same file, so we don't
49                         * need to check that here.
50                         */
51                        (void)DeleteFile(newname);
52                        if (!MoveFile(oldname, newname))
53                                ret = __os_win32_errno();
54                }
55        }
56
57done:   if (ret != 0 && flags == 0)
58                __db_err(dbenv,
59                    "Rename %s %s: %s", oldname, newname, strerror(ret));
60
61        return (ret);
62}
Note: See TracBrowser for help on using the repository browser.