Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

  1. /***
  2. *rename.c - rename file
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines rename() - rename a file
  8. *
  9. *Revision History:
  10. * 06-06-89 PHG Module created, based on asm version
  11. * 03-07-90 GJF Made calling type _CALLTYPE2 (for now), added #include
  12. * <cruntime.h>, fixed compiler warnings and fixed the
  13. * copyright. Also, cleaned up the formatting a bit.
  14. * 03-30-90 GJF Now _CALLTYPE1.
  15. * 07-24-90 SBM Removed '32' from API names
  16. * 09-27-90 GJF New-style function declarator.
  17. * 12-04-90 SRW Changed to include <oscalls.h> instead of <doscalls.h>
  18. * 12-06-90 SRW Added _CRUISER_ and _WIN32 conditionals.
  19. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  20. * 11-01-93 CFW Enable Unicode variant, rip out Cruiser.
  21. * 02-08-95 JWM Spliced _WIN32 & Mac versions.
  22. * 07-01-96 GJF Replaced defined(_WIN32) with !defined(_MAC). Also,
  23. * detab-ed and cleaned up the format a bit.
  24. * 05-17-99 PML Remove all Macintosh support.
  25. *
  26. *******************************************************************************/
  27. #include <cruntime.h>
  28. #include <oscalls.h>
  29. #include <internal.h>
  30. #include <io.h>
  31. #include <tchar.h>
  32. /***
  33. *int rename(oldname, newname) - rename a file
  34. *
  35. *Purpose:
  36. * Renames a file to a new name -- no file with new name must
  37. * currently exist.
  38. *
  39. *Entry:
  40. * _TSCHAR *oldname - name of file to rename
  41. * _TSCHAR *newname - new name for file
  42. *
  43. *Exit:
  44. * returns 0 if successful
  45. * returns not 0 and sets errno if not successful
  46. *
  47. *Exceptions:
  48. *
  49. *******************************************************************************/
  50. int __cdecl _trename (
  51. const _TSCHAR *oldname,
  52. const _TSCHAR *newname
  53. )
  54. {
  55. ULONG dosretval;
  56. /* ask OS to move file */
  57. if (!MoveFile((LPTSTR)oldname, (LPTSTR)newname))
  58. dosretval = GetLastError();
  59. else
  60. dosretval = 0;
  61. if (dosretval) {
  62. /* error occured -- map error code and return */
  63. _dosmaperr(dosretval);
  64. return -1;
  65. }
  66. return 0;
  67. }