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

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