home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / ACCESS.C next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.1 KB  |  63 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - access.c
  3.  *
  4.  * function(s)
  5.  *        access - determines accessibility of a file
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18.  
  19. #include <io.h>
  20. #include <dos.h>
  21. #include <errno.h>
  22.  
  23. /*--------------------------------------------------------------------------*
  24.  
  25. Name        access - determines accessibility of a file
  26.  
  27. Usage        int access(const char *filename, int amode);
  28.  
  29. Prototype in    io.h
  30.  
  31. Description    access checks  a named file  to determine if  it exists and
  32.         whether it can be read, written or executed.
  33.  
  34.         filename points to a string naming the file.
  35.  
  36.         amode  contains a  bit pattern    constructed as    follows:
  37.             06    Check for read and write permission
  38.             04    Check for read    permission
  39.             02    Check for  write permission
  40.             01    Check for execute permission
  41.             00    Check for existence of file
  42.  
  43.  
  44. Return value    If  the   requested  access  is  allowed,   0  is  returned
  45.         otherwise, a  value of -1 is  returned and errno is  set to
  46.         one of    the following:
  47.             ENOENT    Path or file  name not found
  48.             EACCES    Permission denied
  49.  
  50. *----------------------------------------------------------------------------*/
  51. int access(const char *filename, int amode)
  52. {
  53.     register int    attrib;
  54.  
  55.     attrib = _chmod(filename, 0);
  56.     if (attrib == -1)
  57.         return(attrib);
  58.     if ((amode & 0x0002) == 0 || (attrib & FA_RDONLY) == 0)
  59.         return(0);
  60.     errno = EACCES;
  61.     return(-1);
  62. }
  63.