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.

85 lines
2.7 KiB

  1. /***
  2. *unlink.c - unlink a file
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines unlink() - unlink 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. * 07-24-90 SBM Removed '32' from API names
  15. * 09-27-90 GJF New-style function declarators.
  16. * 12-04-90 SRW Changed to include <oscalls.h> instead of <doscalls.h>
  17. * 12-06-90 SRW Added _CRUISER_ and _WIN32 conditionals.
  18. * 01-16-91 GJF ANSI naming.
  19. * 04-10-91 PNT Added _MAC_ conditional
  20. * 03-16-92 PLM MAC verison ccreated from OS/2 version
  21. * 04-10-91 PNT Added _MAC_ conditional (Mac version only)
  22. * 11-02-92 PLM Added directory test and extracted code for remove() (Mac version only)
  23. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  24. * 11-01-93 CFW Enable Unicode variant, rip out Cruiser.
  25. * 02-08-95 JWM Spliced _WIN32 & Mac versions.
  26. * 07-01-96 GJF Replaced defined(_WIN32) with !defined(_MAC). Also,
  27. * detab-ed and cleaned up the format a bit.
  28. * 05-17-99 PML Remove all Macintosh support.
  29. *
  30. *******************************************************************************/
  31. #include <cruntime.h>
  32. #include <oscalls.h>
  33. #include <internal.h>
  34. #include <io.h>
  35. #include <tchar.h>
  36. /***
  37. *int _unlink(path) - unlink(delete) the given file
  38. *
  39. *Purpose:
  40. * This version deletes the given file because there is no
  41. * distinction between a linked file and non-linked file.
  42. *
  43. * NOTE: remove() is an alternative entry point to the _unlink()
  44. * routine* interface is identical.
  45. *
  46. *Entry:
  47. * _TSCHAR *path - file to unlink/delete
  48. *
  49. *Exit:
  50. * returns 0 if successful
  51. * returns -1 and sets errno if unsuccessful
  52. *
  53. *Exceptions:
  54. *
  55. *******************************************************************************/
  56. int __cdecl _tremove (
  57. const _TSCHAR *path
  58. )
  59. {
  60. ULONG dosretval;
  61. if (!DeleteFile((LPTSTR)path))
  62. dosretval = GetLastError();
  63. else
  64. dosretval = 0;
  65. if (dosretval) {
  66. /* error occured -- map error code and return */
  67. _dosmaperr(dosretval);
  68. return -1;
  69. }
  70. return 0;
  71. }
  72. int __cdecl _tunlink (
  73. const _TSCHAR *path
  74. )
  75. {
  76. /* remove is synonym for unlink */
  77. return _tremove(path);
  78. }