home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * ACCESS.C Check File Accessibility
- *
- * (c)Copyright 1990, Matthew Dillon, All Rights Reserved
- */
-
- #include <libraries/dos.h>
- #include <stdlib.h>
-
- typedef struct FileInfoBlock FIB;
-
- int
- access(name, mode)
- const char *name;
- int mode;
- {
- FIB *fib = malloc(sizeof(FIB));
- int r = -1;
-
- if (fib) {
- BPTR lock;
- if (lock = Lock(name, SHARED_LOCK)) {
- if (Examine(lock, fib)) {
- long prot = fib->fib_Protection;
-
- r = 0;
- if (mode & 4) { /* r */
- if (prot & 8) /* no read perm */
- r = -1;
- }
- if (mode & 2) { /* w */
- if (prot & 4) /* no write perm */
- r = -1;
- }
- if (mode & 1) { /* x */
- if (prot & 2) /* no execute perm */
- r = -1;
- }
- }
- UnLock(lock);
- }
- free(fib);
- }
- return(r);
- }
-
-