#include #include bool isReadable(char* filename) { bool readable = false; struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL); if (!fib) { printf("Not enough memory!\n"); return false; } BPTR pLock = IDOS->Lock((STRPTR)filename, SHARED_LOCK); if (pLock) { if (IDOS->Examine(pLock, fib) != DOSFALSE) { if (fib->fib_Protection == FIBB_READ) { readable = true; } else { printf("Fib read status was false.\n"); } } else { printf("The examine operation failed.\n"); } IDOS->UnLock(pLock); } else { printf("Couldn't acquire the lock.\n"); } IDOS->FreeDosObject(DOS_FIB, fib); return readable; } bool isWritable(char* filename) { bool writable = false; struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL); if (!fib) { printf("Not enough memory!"); return false; } BPTR pLock = IDOS->Lock((STRPTR)filename, SHARED_LOCK); if (pLock) { if (IDOS->Examine(pLock, fib) != DOSFALSE) { if (fib->fib_Protection == FIBB_WRITE) { writable = true; } else { printf("Fib write status was false.\n"); } } else { printf("The examine operation failed.\n"); } IDOS->UnLock(pLock); } else { printf("Couldn't acquire the lock.\n"); } IDOS->FreeDosObject(DOS_FIB, fib); return writable; } int main(int argc, char* argv[]) { char* readonly = "readonly.txt"; char* readwrite = "readwrite.txt"; if (isReadable(readonly)) { printf("%s is readable.\n", readonly); } else { printf("%s is not readable.\n", readonly); } if (isWritable(readonly)) { printf("%s is writable.\n", readonly); } else { printf("%s is not writable.\n", readonly); } if (isReadable(readwrite)) { printf("%s is readable.\n", readwrite); } else { printf("%s is not readable.\n", readwrite); } if (isWritable(readwrite)) { printf("%s is writable.\n", readwrite); } else { printf("%s is not writable.\n", readwrite); } return 0; }