Welcome, Guest. Please login or register.

Author Topic: Retrieving FileSize in bytes  (Read 3002 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JettahTopic starter

  • Full Member
  • ***
  • Join Date: Nov 2003
  • Posts: 115
    • Show all replies
Retrieving FileSize in bytes
« on: January 12, 2004, 02:28:54 PM »
Hi,

I'm having some troubles in retrieving the number of bytes a file occupies. The documentation on this subject is not entirely clear (to me, at least).

The following piece of code is used:

struct FileInfoBlock *fib;

if (fib = AllocDosObjectTags(DOS_FILEHANDLE, ADO_FH_Mode))
  {if (Examine(, fib))
     {fib_Size>;
     }
   FreeDosObject(DOS_FILEHANDLE, fib);
  }

The program crashes when reaching AllocDosObjectTags() (or AllocDosTags for that matter).
I can find documentation about DOS_FILEHANDLE /* few people need it */, but I cannot find anything on ADO_FH_Mode! I have a peculiar feeling that,as it is a tag list, it requires a certain value, like this:

ADO_FH_Mode, , TAG_END

But what has to be supplied for ???. I can't find anything about it.
Or am I fully lost in paradise of Amiga software developement?

Help! HELP! Mommy, please help me!

Regards,

Tjitte

P.S.: When it (my small contribution of software) gets published someday, your name will be mentioned in the accompanying README!
Sometimes I wish I was Mt Vesuvius: laying on my back in the sun while smoking a bit and everybody seeing me would say: \\"Look! He\\\'s active!\\" (author unknown to me)
 

Offline JettahTopic starter

  • Full Member
  • ***
  • Join Date: Nov 2003
  • Posts: 115
    • Show all replies
Re: Retrieving FileSize in bytes
« Reply #1 on: January 12, 2004, 03:15:42 PM »
@itix:

Thanks for your reply.

But, ehm, it, eh, still does not perform the way I intended...

Changed the code to:
struct FileInfoBlock *fib;

if ((struct FileInfoBlock *)fib = AllocDosObject(DOS_FIB, TAG_END))
  {if (Examine(, fib)) fib_Size>;
   FreeDosObject(DOS_FIB, fib);
   }

It still crashes...

Regards,

Tjitte
Sometimes I wish I was Mt Vesuvius: laying on my back in the sun while smoking a bit and everybody seeing me would say: \\"Look! He\\\'s active!\\" (author unknown to me)
 

Offline JettahTopic starter

  • Full Member
  • ***
  • Join Date: Nov 2003
  • Posts: 115
    • Show all replies
Re: Retrieving FileSize in bytes
« Reply #2 on: January 12, 2004, 10:27:25 PM »
Quote

itix wrote:
Quote

if ((struct FileInfoBlock *)fib = AllocDosObject(DOS_FIB, TAG_END))


Why you have "(struct FileInfoBlock *)fib" there?


It's there because AllocDosObject() returns a void *.

In the meantime I've isolated the problem into a separate piece of proza:

#include
#include
#include
#include

void main(void)
{struct FileInfoBlock *fib;
  struct Library *DosBase;
  BPTR File, x;
  char *FileName = "RAM:T/Command-0-T5";

  if (DosBase = OpenLibrary("dos.library", 40L))
    {if (File = Lock(FileName, SHARED_LOCK))
      {if ((struct FileInfoBlock *)fib = AllocDosObjectTags(DOS_FIB, TAG_END))
        {if (Examine(File, fib))
          {printf("Name = %s\n", fib->fib_Name);
           printf("Type = %s\n", (fib->fib_DirEntryType > 0) ? "Directory" : "File";
           printf("Size = %ld\n", fib->fib_Size);
          }
        else printf("ERROR\n");
        FreeDosObject(DOS_FIB, fib);
       }
     if (x = Open(FileName, MODE_OLDFILE))
       {printf("File opened\n");
         Close(x);
       }
     UnLock(File);
    }
   else printf("ERROR: No file locked\n");
   CloseLibrary(DosBase);
   }
  else printf("ERROR: No library opened"\n");
}

This gave me the requested results without troubles. So I draw the conclusion that I'm on the very brink of insight into the matter!

Thanks for all your concern to all of you.

Regards,

Tjitte
Sometimes I wish I was Mt Vesuvius: laying on my back in the sun while smoking a bit and everybody seeing me would say: \\"Look! He\\\'s active!\\" (author unknown to me)
 

Offline JettahTopic starter

  • Full Member
  • ***
  • Join Date: Nov 2003
  • Posts: 115
    • Show all replies
Re: Retrieving FileSize in bytes
« Reply #3 on: January 13, 2004, 08:00:12 PM »
Quote

PiR wrote:
Quote
(struct FileInfoBlock *)fib = AllocDosObject(DOS_FIB, TAG_END)


Yep, you have it on the wrong side.
You mean:
fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, TAG_END)


Silly me! You are perfectly correct. Thanks mate! And remember: whenever the piece of proza, in which the construct is used, ever gets published, your name will shine in the accompanying README!

Bye!

Topic closed.
Tjitte
Sometimes I wish I was Mt Vesuvius: laying on my back in the sun while smoking a bit and everybody seeing me would say: \\"Look! He\\\'s active!\\" (author unknown to me)