home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / posix / sys / stat / chmod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-27  |  709 b   |  27 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <sys/stat.h>
  4. #include <io.h>
  5.  
  6. int
  7. chmod(const char *filename, int pmode)
  8. {
  9.   int dmode;
  10.   unsigned attr = _chmod(filename, 0, 0);
  11.  
  12.   if (attr == -1)
  13.     return -1;
  14.  
  15.   if(pmode & S_IWUSR)           /* Only implemented toggle is write/nowrite */
  16.     dmode = 0;                  /* Normal file */
  17.   else
  18.     dmode = 1;                  /* Readonly file */
  19.  
  20.   /* Must clear the directory and volume bits, otherwise 214301 fails.
  21.      Unused bits left alone (some network redirectors use them).  */
  22.   if (_chmod(filename, 1, (attr & 0xffe6) | dmode) == -1)
  23.     return -1;
  24.   return 0;
  25. }
  26.  
  27.