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

  1. /*------------------------------------------------------------------------
  2.  * filename - chmod.c
  3.  *
  4.  * function(s)
  5.  *        chmod - changes access mode of 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 <sys\stat.h>
  20.  
  21.  
  22. /*-------------------------------------------------------------------------*
  23.  
  24. Name            chmod - changes access mode of file
  25.  
  26. Usage           #include <sys\stat.h>
  27.                 int chmod(const char *filename, int permiss);
  28.  
  29. Prototype in    io.h
  30.  
  31. Description     chmod  sets   the  file access  permissions  of   the  file
  32.                 according to the mask given by permiss.
  33.  
  34.                 filename points to a string naming the file
  35.  
  36.                 permiss can contain  one or both of the  symbolic constants
  37.                 S_IWRITE and S_IREAD:
  38.  
  39.                 Value of permiss        Access Permission
  40.                 S_IWRITE                Permission to write
  41.                 S_IREAD                 Permission to read
  42.                 S_IREAD | S_IWRITE      Permission to read and write
  43.  
  44. Return value    Upon  successfully  changing  the  file access  mode, chmod
  45.                 returns 0 otherwise, it returns a  value of -1 and errno is
  46.                 set to one of the following:
  47.  
  48.                 ENOENT  Path or file name not found
  49.                 EACCES  Permission denied
  50.  
  51. *---------------------------------------------------------------------------*/
  52. int _FARFUNC chmod(const char *filename, int permiss)
  53. {
  54.   register int  attrib;
  55.  
  56.   attrib = _chmod(filename, 0);
  57.   if (attrib == -1)
  58.     return(attrib);
  59.   attrib &= ~FA_RDONLY;
  60.   if ((permiss & S_IWRITE) == 0)
  61.     attrib |= FA_RDONLY;
  62.   attrib = _chmod(filename, 1, attrib);
  63.   if (attrib == -1)
  64.     return(attrib);
  65.   return(0);
  66. }
  67.