Source code of Windows XP (NT5)
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.

88 lines
2.7 KiB

  1. /***
  2. *chmod.c - change file attributes
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines _chmod() - change file attributes
  8. *
  9. *Revision History:
  10. * 06-06-89 PHG Module created, based on asm version
  11. * 11-10-89 JCR Replaced DOS32QUERYFILEMODE with DOS32QUERYPATHINFO
  12. * 03-07-90 GJF Made calling type _CALLTYPE2 (for now), added #include
  13. * <cruntime.h>, fixed copyright and fixed compiler
  14. * warnings. Also, cleaned up the formatting a bit.
  15. * 03-30-90 GJF Now _CALLTYPE1.
  16. * 07-24-90 SBM Removed '32' from API names
  17. * 09-27-90 GJF New-style function declarator.
  18. * 12-04-90 SRW Changed to include <oscalls.h> instead of <doscalls.h>
  19. * 12-06-90 SRW Added _CRUISER_ and _WIN32 conditionals.
  20. * 01-16-91 GJF ANSI naming.
  21. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  22. * 11-01-93 CFW Enable Unicode variant, rip out Cruiser.
  23. * 02-08-95 JWM Spliced _WIN32 & Mac versions.
  24. * 07-01-96 GJF Replaced defined(_WIN32) with !defined(_MAC). Also,
  25. * detab-ed and cleaned up the format a bit.
  26. * 05-17-99 PML Remove all Macintosh support.
  27. *
  28. *******************************************************************************/
  29. #include <cruntime.h>
  30. #include <oscalls.h>
  31. #include <internal.h>
  32. #include <io.h>
  33. #include <sys\types.h>
  34. #include <sys\stat.h>
  35. #include <tchar.h>
  36. /***
  37. *int _chmod(path, mode) - change file mode
  38. *
  39. *Purpose:
  40. * Changes file mode permission setting to that specified in
  41. * mode. The only XENIX mode bit supported is user write.
  42. *
  43. *Entry:
  44. * _TSCHAR *path - file name
  45. * int mode - mode to change to
  46. *
  47. *Exit:
  48. * returns 0 if successful
  49. * returns -1 and sets errno if not successful
  50. *
  51. *Exceptions:
  52. *
  53. *******************************************************************************/
  54. int __cdecl _tchmod (
  55. const _TSCHAR *path,
  56. int mode
  57. )
  58. {
  59. DWORD attr;
  60. attr = GetFileAttributes((LPTSTR)path);
  61. if (attr == 0xffffffff) {
  62. /* error occured -- map error code and return */
  63. _dosmaperr(GetLastError());
  64. return -1;
  65. }
  66. if (mode & _S_IWRITE) {
  67. /* clear read only bit */
  68. attr &= ~FILE_ATTRIBUTE_READONLY;
  69. }
  70. else {
  71. /* set read only bit */
  72. attr |= FILE_ATTRIBUTE_READONLY;
  73. }
  74. /* set new attribute */
  75. if (!SetFileAttributes((LPTSTR)path, attr)) {
  76. /* error occured -- map error code and return */
  77. _dosmaperr(GetLastError());
  78. return -1;
  79. }
  80. return 0;
  81. }