Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: gazsp on October 29, 2005, 10:36:41 PM
-
Me again :-)
Any ideas anybody? Can I get it from using Lock()?
-
dos.library/Examine
See dos/dos.h 'struct FileInfoBlock', fib_Size holds the size.
-
Cool, cheers. I used to know that one but I haven't done any Amiga programming for a while :-)
-
a other method i used a lot is a double call of Seek(), it returns the postition of the last i/o call
Seek(filehd, 0, OFFSET_END);
len = Seek(filehd, 0, OFFSET_BEGINNING);
the 1st seeks to the end of the file so the 2nd call returns the position of the last dos i/o
-
@DariusB
I left that method out for a reason: It's ultraslow with ffs and large files. It should be avoided.
-
Or use lstat()
#include
struct stat *stat_info;
lstat("filename", stat_info);
printf("The file is %d bytes in size", stat_info->st_size);
Or something like that anyway. I think the beers are having an adverse affect on my memory :pint:
Just noticed that original post was October last year. I hope he's figured it out by now!
-
@Castellen
#include <sys/stat.h>
#include <stdio.h>
struct stat stat_info;
if (lstat("filename", &stat_info) != -1)
{
printf("The file is %d bytes in size\n", stat_info.st_size);
}
else
{
perror("lstat");
}
-
Yep, makes sense to use it without using structure pointers like that.
Not sure if this is the most efficient way to do the job, but also in the "stat" structure are things like file date, file comments, etc, which can be useful.
It's a good general purpose "give me every information available about a file" type of function.