home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-4 / BDSLIB.ARK / FACCESS.C < prev    next >
Text File  |  1983-07-15  |  1KB  |  31 lines

  1. /*
  2.  * Faccess
  3.  * Based roughly on the U**X system call, it accepts a filename 
  4.  * and a mode (0 - exists, 2 - write, and 4 - read). If the test
  5.  * is successful 0 returned. If the test is unsuccessful or the
  6.  * file could not be found -1 is returned. This helps to remedy
  7.  * some of the 'Bdos Err On A: File R/O'  ugliness.
  8.  * Edit of 7/1/83
  9.  */
  10.  
  11. faccess(name,mode)
  12. char *name;
  13. int mode;
  14. {
  15.     char *byte, c;
  16.     fcb address;
  17.  
  18.     setfcb(address,name);
  19.     if ((c=bdos(17,&address)) == 255)
  20.         return ERROR;         /* file not found    */
  21.     byte =(0x80 + (c * 32) + _MBYTE); /* permission byte    */
  22.     if (mode == 0) return 0;    /* file exists        */
  23.     if ((*byte & '\200') == 0) {
  24.         if (mode == 1) return 0; /* execute permission    */
  25.         if (mode == 2) return 0; /* write permission    */
  26.         if (mode == 4) return 0; /* read permission    */
  27.     }
  28.     else if (mode == 2) return ERROR;   /* readonly file    */
  29.     else return ERROR;         /* unknown mode    */
  30. }
  31.