All pastes #756632 Raw Edit

Something

public text v1 · immutable
#756632 ·published 2007-10-31 17:02 UTC
rendered paste body
#include <stdio.h>
#include <proto/dos.h>

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) {
			printf("Protection: %i", fib->fib_Protection);
			printf(", Masked: %i\n", fib->fib_Protection & FIBB_READ);

					
			/*if (fib->fib_Protection == FIBB_READ) {
				readable = true;
			} else {
				printf("Fib read status was false.\n");
			}*/
		} else {
			printf("The read examine operation failed.\n");
		}
		IDOS->UnLock(pLock);
	} else {
		printf("Couldn't acquire the read 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) {
			printf("Protection: %i", fib->fib_Protection);
			printf(", Masked: %i\n", fib->fib_Protection & FIBB_WRITE);
			
			/*if (fib->fib_Protection == FIBB_WRITE) {
				writable = true;
			} else {
				printf("Fib write status was false.\n");
			}*/
		} else {
			printf("The write examine operation failed.\n");
		}
		IDOS->UnLock(pLock);
	} else {
		printf("Couldn't acquire the write lock.\n");
	}
	
	IDOS->FreeDosObject(DOS_FIB, fib);
	return writable;
}

int main(int argc, char* argv[]) {
	char* readonly = "RAM:Testing/readonly.txt";
	char* readwrite = "RAM:Testing/readwrite.txt";
	
	if (isReadable(readonly)) {
		printf("%s is readable.\n\n", readonly);
	} else {
		printf("%s is not readable.\n\n", readonly);
	}
	
	if (isWritable(readonly)) {
		printf("%s is writable.\n\n", readonly);
	} else {
		printf("%s is not writable.\n\n", readonly);
	}
	
	if (isReadable(readwrite)) {
		printf("%s is readable.\n\n", readwrite);
	} else {
		printf("%s is not readable.\n\n", readwrite);
	}
	
	if (isWritable(readwrite)) {
		printf("%s is writable.\n\n", readwrite);
	} else {
		printf("%s is not writable.\n\n", readwrite);
	}
	
	return 0;
}