home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC1.ZIP / ACCESS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.0 KB  |  61 lines

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