All pastes #756582 Raw Edit

Something

public text v1 · immutable
#756582 ·published 2007-10-31 16:20 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\n", fib->fib_Protection);
   printf("Entry type: %i\n", fib->fib_EntryType);
  
   /*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) {
   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", 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;
}