os_rename.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:1k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1997, 1998, 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  */
  7. #include "db_config.h"
  8. #ifndef lint
  9. static const char revid[] = "$Id: os_rename.c,v 1.2 2000/06/13 19:52:19 dda Exp $";
  10. #endif /* not lint */
  11. #include "db_int.h"
  12. #include "os_jump.h"
  13. /*
  14.  * __os_rename --
  15.  * Rename a file.
  16.  */
  17. int
  18. __os_rename(dbenv, old, new)
  19. DB_ENV *dbenv;
  20. const char *old, *new;
  21. {
  22. int ret;
  23. ret = 0;
  24. if (__db_jump.j_rename != NULL) {
  25. if (__db_jump.j_rename(old, new) == -1)
  26. ret = __os_get_errno();
  27. }
  28. else {
  29. /* Normally we would use a single MoveFileEx call with
  30.  * MOVEFILE_REPLACE_EXISTING flag to simulate Unix rename().
  31.  * But if the target file exists, and the two files' 8.3
  32.  * names are identical, a Windows bug causes the target file
  33.  * to be deleted, but the original file will not be renamed,
  34.  * and an ENOENT error will be returned.  (See MSDN for a
  35.  * description of the bug).
  36.  *
  37.  * After the failed call, a MoveFile seems to perform
  38.  * the rename correctly (even another call to MoveFileEx
  39.  * does not)!  The expense of this extra call only occurs
  40.  * on systems with the bug: Windows/98, for one, but
  41.  * apparently not Windows/NT and Windows/2000.
  42.  */
  43. if (MoveFileEx(old, new, MOVEFILE_REPLACE_EXISTING) != TRUE)
  44. ret = __os_win32_errno();
  45. if (ret == ENOENT && MoveFile(old, new) == TRUE)
  46. ret = 0;
  47. }
  48. if (ret != 0)
  49. __db_err(dbenv, "Rename %s %s: %s", old, new, strerror(ret));
  50. return (ret);
  51. }