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.

86 lines
2.9 KiB

  1. /***
  2. *access.c - access function
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file has the _access() function which checks on file accessability.
  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-09-91 PNT Added _MAC_ conditional
  22. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  23. * 12-07-93 CFW Rip out Cruiser, enable wide char.
  24. * 02-08-95 JWM Spliced _WIN32 & Mac versions.
  25. * 07-01-96 GJF Replaced defined(_WIN32) with !defined(_MAC). Also,
  26. * detab-ed and cleaned up the format a bit.
  27. * 05-17-99 PML Remove all Macintosh support.
  28. *
  29. *******************************************************************************/
  30. #include <cruntime.h>
  31. #include <io.h>
  32. #include <oscalls.h>
  33. #include <stdlib.h>
  34. #include <errno.h>
  35. #include <msdos.h>
  36. #include <internal.h>
  37. #include <tchar.h>
  38. /***
  39. *int _access(path, amode) - check whether file can be accessed under mode
  40. *
  41. *Purpose:
  42. * Checks to see if the specified file exists and can be accessed
  43. * in the given mode.
  44. *
  45. *Entry:
  46. * _TSCHAR *path - pathname
  47. * int amode - access mode
  48. * (0 = exist only, 2 = write, 4 = read, 6 = read/write)
  49. *
  50. *Exit:
  51. * returns 0 if file has given mode
  52. * returns -1 and sets errno if file does not have given mode or
  53. * does not exist
  54. *
  55. *Exceptions:
  56. *
  57. *******************************************************************************/
  58. int __cdecl _taccess (
  59. const _TSCHAR *path,
  60. int amode
  61. )
  62. {
  63. DWORD attr;
  64. attr = GetFileAttributes((LPTSTR)path);
  65. if (attr == 0xffffffff) {
  66. /* error occured -- map error code and return */
  67. _dosmaperr(GetLastError());
  68. return -1;
  69. }
  70. /* no error; see if returned premission settings OK */
  71. if ( (attr & FILE_ATTRIBUTE_READONLY) && (amode & 2) ) {
  72. /* no write permission on file, return error */
  73. errno = EACCES;
  74. _doserrno = E_access;
  75. return -1;
  76. }
  77. else
  78. /* file exists and has requested permission setting */
  79. return 0;
  80. }