I was wondering if there is an easy way to get a file's size before
reading the entire thing from within a C program on the Amiga.
I realize the file read functions tend to return the total number of bytes
read, etc. But, I also know that AmigaDOS stores file sizes in some
fashion, as evidenced by the LIST command. Is there a way that will allow
me to access this information in a quick way.
Mostly I want to use this to ease the job of allocating a buffer in RAM
for a file on disk (I can do the work off disk, or only buffer the file a
bit at a time - but I'd like to read the whole thing in advance when
possible).
- Porter Woodward
> Hi all,
>
> I was wondering if there is an easy way to get a file's size before
> reading the entire thing from within a C program on the Amiga.
Here is a simple way of doing it:
FILE *f;
long l;
f=fopen("filename","rb");
fseek(f,0,2); /* Places the file-pointer at the end of the file */
l=ftell(f); /* Get the file-pointer's position in the file.
Because we placed the pointer at the end of the
file, we get the file's size */
fclose(f);
If you wanted to know how to do it in Amiga-specific code, I'm sorry I
can't help you.
But, as always, isn't it good to have code that's easy to port to other
systems???
/Tommy Savela (sav...@lysator.liu.se)
WW> I was wondering if there is an easy way to get a file's size before
WW> reading the entire thing from within a C program on the Amiga.
BPTR fh;
ULONG size;
fh = Open("file",MODE_OLDFILE);
size = Seek(fh,0,OFFSET_END);
Close(fh);
WW> read, etc. But, I also know that AmigaDOS stores file sizes in some
WW> fashion, as evidenced by the LIST command. Is there a way that will
WW> allow me to access this information in a quick way.
Yes, the info is also stored in a struct FileInfoBlock, which you can
acquire using the Lock() and Examine() functions, but the above method is
actually simpler. I normally only use Examine() if I need more than just
the filesize.
-- Via DLG Pro v1.15
/* Jeff Grimmett (Jeff_G...@elric.maximumaccess.com)
** DLG Development (http://www.ald.net/dlg)
** The home of DLG Pro (Fido: 1:202/720.0 -- (619) 549 7742)
****************************************************************/
The Amiga Seek() is to be called with a filehandle got by Open(),
you never know what a FILE structure looks like when using the compilers
functions.
: can't help you.
: But, as always, isn't it good to have code that's easy to port to other
: systems???
yep. depends on the other stuff he does, window stuff is not ANSI C yet ;)
I wrote my own fseek()/ftell() routines basing on Seek(),
so my source is ANSI :)
but it wouldn't help you to adapt that code (I use my own FILE structure).
So here's an _untested_ version I cut-pasted together, no warranties for
HD-crash, test it on floppy with HD partitions disabled ;)
/* -1 is error */
int filelen(amigahandle_got_from_Open *fp)
{
int oldpos;
oldpos=Seek(fp,0,1 /* 1:seek to end */)
if (oldpos==-1) return -1;
return Seek(fp,0,0 /* 0:current */);
}
If Seek() would return currentpos instead of oldpos, then 1 call
would be enough, gnagna. Testing it on floppy I found it doesn't
take much time. Anyway better than the len=read(infinite)
approach you do if you only know those 3 doslib calls ;)
:
: /Tommy Savela (sav...@lysator.liu.se)
:
-------------------------------------------------------------------------
fisc...@Informatik.TU-Muenchen.DE (Juergen "Rally" Fischer) =:)
http://www.informatik.tu-muenchen.de/~fischerj/
^- dont forget this char
In article <519ssc$r...@news-central.tiac.net>, wood...@tiac.net (Porter Woodward) writes:
>I was wondering if there is an easy way to get a file's size before
>reading the entire thing from within a C program on the Amiga.
>
>I realize the file read functions tend to return the total number of bytes
>read, etc. But, I also know that AmigaDOS stores file sizes in some
>fashion, as evidenced by the LIST command. Is there a way that will allow
>me to access this information in a quick way.
>
>Mostly I want to use this to ease the job of allocating a buffer in RAM
>for a file on disk (I can do the work off disk, or only buffer the file a
>bit at a time - but I'd like to read the whole thing in advance when
>possible).
Lock() then Examine() is the fastest method.
Open(), Seek(fh,0,OFFSET_END), size = Seek(fh,0,OFFSET_BEGINNING) will
work, too, but is much slower. *Might* be worthwhile since you ARE
going to Open() the file anyway, but...
--
---------------
Jim Cooper
(ja...@unx.sas.com) bix: jcooper
Any opinions expressed herein are mine (Mine, all mine! Ha, ha, ha!),
and not necessarily those of my employer.
Out of sorts? Heck, I'm out of *most* algorithms!
Volker
Depending on the file size that you are working with, a Seek() can
be fairly slow. In this case though, it is unlikely. If you expect
to work on large files, use Examine(). Note that Examine() won't
necessarily reflect the current size for opened writable files.
While changing a file, Seek on the fh is reliable.
--
Heinz Wrobel Private Mail: he...@hwg.muc.de
My private FAX: +49 89 850 51 25, I prefer email
WW>> I was wondering if there is an easy way to get a file's size before
WW>> reading the entire thing from within a C program on the Amiga.
JG> BPTR fh;
JG> ULONG size;
JG> fh = Open("file",MODE_OLDFILE);
JG> size = Seek(fh,0,OFFSET_END);
JG> Close(fh);
size will be always equal to 0. Seek returns the starting position: you
should do:
Seek( fh, 0, OFFSET_END );
size = Seek( fh, 0, OFFSET_BEGINNING );
Bye
Wiz
-- __
__ /// Fidonet: 2:332/502 (Simone Tellini)
\\\/// E-Mail: 0380...@mbox.it.net
\X// WWW: http://www.pragmanet.it/~tellini/main.html
Advanced: (adj.) doesn't work yet, but it's pretty close.
Tommy Savela (sav...@lysator.liu.se) wrote:
>On 12 Sep 1996, Porter Woodward wrote:
>> Hi all,
>>
>> I was wondering if there is an easy way to get a file's size before
>> reading the entire thing from within a C program on the Amiga.
>Here is a simple way of doing it:
> FILE *f;
> long l;
> f=fopen("filename","rb");
> fseek(f,0,2); /* Places the file-pointer at the end of the file */
> l=ftell(f); /* Get the file-pointer's position in the file.
> Because we placed the pointer at the end of the
> file, we get the file's size */
> fclose(f);
>If you wanted to know how to do it in Amiga-specific code, I'm sorry I
>can't help you.
>But, as always, isn't it good to have code that's easy to port to other
>systems???
> /Tommy Savela (sav...@lysator.liu.se)
Isn't int=filelenght(filehandle) a standard ANSI C function?
At least I've seen it around in many computers.
#include <IO.h>
/=============================================================================\
| Fabio Bizzetti - Maverick/independent - bizz...@mbox.vol.it |
|=============================================================================|
| Developing 68x86 and HLAOOP, the programming languages you were waiting for |
\=============================================================================/
In that case ExamineFH() might be an even better choice.
--
Home: Olaf Barthel, Brabeckstrasse 35, D-30559 Hannover
Net: ol...@sourcery.han.de
>acquire using the Lock() and Examine() functions, but the above method is
>actually simpler. I normally only use Examine() if I need more than just
HW> Depending on the file size that you are working with, a Seek() can
HW> be fairly slow. In this case though, it is unlikely. If you expect
HW> to work on large files, use Examine(). Note that Examine() won't
HW> necessarily reflect the current size for opened writable files.
HW> While changing a file, Seek on the fh is reliable.
Yah, Seek() has that baggage, but all things being equal... :-) I've
actually experienced problems with Examine() in the past, making me less
eager to use it (though you do mention a good point I hadn't thought of).
WW>> I was wondering if there is an easy way to get a file's size before
WW>> reading the entire thing from within a C program on the Amiga.
JG> BPTR fh;
JG> ULONG size;
JG> fh = Open("file",MODE_OLDFILE);
JG> size = Seek(fh,0,OFFSET_END);
JG> Close(fh);
T> size will be always equal to 0. Seek returns the starting position:
T> you
T> should do:
T> Seek( fh, 0, OFFSET_END );
T> size = Seek( fh, 0, OFFSET_BEGINNING );
Hm... could be I have gotten confused from working on three different
platforms and having to translate back and forth from ANSI to Amiga to
HP/UX C. Thanks for the correction. For my Amiga programming I use the
FileSize() command in dlg.library since that's what I always work with.
(that function, BTW, uses Examine(). I didn't write that part, but see no
reason to change it if it ain't broken :-)
In article <1321...@sourcery.han.de> "Olaf Barthel" <ol...@sourcery.han.de> writes:
>
> In that case ExamineFH() might be an even better choice.
But not all FileSystems support the dos packet for this function!
<ehb
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: latin1
Comment: public key on request: reque...@draco.prima.ruhr.de
iQCVAwUBMjvnfCVbL+k+Kh4xAQGsQwQAqC2PH9ZOhYDCrVVHGjLD55cbOm7TWddD
wwfHDiWt3H6qV6gnV+T/gZ+xLnNRombqjCfCZ8TN5FqyNxoFkZOdDxKT0oso7/kk
P4Uuhn/KFiKAgPyf9oSUjnfHi+lA9sqNdm4P3Jpapdl6FJx1GYI3CxvePRzSoaXQ
oH1SAh5gTlY=
=/Q1Z
-----END PGP SIGNATURE-----
--
greetings from draco.prima.ruhr.de
Edwin H. Bielawski
On 13-Sep-96 16:07:53 James Cooper wrote about Re: Easy way to get file size?
in comp.sys.amiga.programmer:
>Open(), Seek(fh,0,OFFSET_END), size = Seek(fh,0,OFFSET_BEGINNING) will
>work, too, but is much slower. *Might* be worthwhile since you ARE
>going to Open() the file anyway, but...
...as there is ExamineFH()...
--
<> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
_ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
\X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
And all the Borg left was this copy of Windows...
...Open() & Seek() code deleted
> Hm... could be I have gotten confused from working on three different
> platforms and having to translate back and forth from ANSI to Amiga to
> HP/UX C. Thanks for the correction. For my Amiga programming I use the
> FileSize() command in dlg.library since that's what I always work with.
> (that function, BTW, uses Examine(). I didn't write that part, but see
no
> reason to change it if it ain't broken :-)
#include <dos.h>
#include <proto/dos.h>
int file_size(unsigned char *fname)
{
__aligned struct FileInfoBlock info;
BPTR lock;
if (!(lock=Lock(fname,ACCESS_READ)))
return(-1);
if (!Examine(lock,&info))
{
UnLock(lock);
return(-2);
}
UnLock(lock);
return(info.fib_Size); // return size of file in bytes (bite
size file? :)
}
--
jo...@peaka.net
Q: What do software managers keep as pets?
A: 'C' monkeys.
Juergen "Rally" Fischer (fisc...@Informatik.TU-Muenchen.DE) wrote about Re: Easy way to get file size?:
>Tommy Savela (sav...@lysator.liu.se) wrote:
>: On 12 Sep 1996, Porter Woodward wrote:
>: > I was wondering if there is an easy way to get a file's size before
>: > reading the entire thing from within a C program on the Amiga.
>:
>: Here is a simple way of doing it:
>:
<using fseek()>
>/* -1 is error */
>int filelen(amigahandle_got_from_Open *fp)
>{
<using Seek()>
>}
Seek()ing/fseek()ing to EOF takes much time because all file extension
blocks must be read, so there may be much (and possibly lengthy) drive
activity. Better Lock() the file and Examine() it or use ExamineFH().
However, this technique is not possible with ANSI functions.
Greetings
--
Christian Wasner (CRISI/PHANTASM)
Christia...@hamburg.netsurf.de
Q: How do I get the X11 sources ?
A: Post DPaint2 into comp.sys.amiga.misc.
Heinz Wrobel (he...@hwg.muc.de) wrote about Re: Easy way to get file size?:
>to work on large files, use Examine(). Note that Examine() won't
>necessarily reflect the current size for opened writable files.
>While changing a file, Seek on the fh is reliable.
This also counts for Seek(). If multiple processes opened the file
non-exclusively, its length may increase immediately after Seek()ing
to its end. However, common sense tells me that it may not become
smaller, at least with Amiga OS.
Edwin H. Bielawski (e...@draco.prima.ruhr.de) wrote about Re: Easy way to get file size?:
>In article <1321...@sourcery.han.de> "Olaf Barthel" <ol...@sourcery.han.de>
>writes:
>>
>> In that case ExamineFH() might be an even better choice.
>But not all FileSystems support the dos packet for this function!
So what ? Upgrade those filesysystems or throw them away if there is
none. Kickstart 2.0 is out for some years now, at last.
In article <602.6836...@hamburg.netsurf.de> Christia...@hamburg.netsurf.de (Christian Wasner) writes:
>
> Edwin H. Bielawski (e...@draco.prima.ruhr.de) wrote about Re: Easy way to get file size?:
>
> >In article <1321...@sourcery.han.de> "Olaf Barthel" <ol...@sourcery.han.de>
> >writes:
> >>
> >> In that case ExamineFH() might be an even better choice.
>
> >But not all FileSystems support the dos packet for this function!
>
> So what ? Upgrade those filesysystems or throw them away if there is
> none. Kickstart 2.0 is out for some years now, at last.
>
OK, you'r right, but where is the update for the original WB3.1
CD FileSystem ??? What ist the reason for a version number 40,
when this FileSystem only supports Kick 1.3 packets? :(((
<ehb
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: latin1
Comment: public key on request: reque...@draco.prima.ruhr.de
iQCVAwUBMkKoLiVbL+k+Kh4xAQEHJQQAmy/vgXQVVbHKjg/DWZLZ63jJBs9xdocF
nzdxw0h0TNCE2mlZd9y/jrc5b9z4W3pS7I4pRUyOU9/UmIDS5XamzaaxattHFPvk
0/tx6btIXWZQpptQnxEVv1IX7sZQ6h3RZk4fUI//xR30X8jAntP8ylN+XJXCMloS
9ePAQZqurqU=
=voFP
The CDFileSystem used to be a CDTV and CD32 Kickstart ROM
module that eventually became a disk-resident filing system. That's
the reason for the V40 label. 2.0 packets would be a desirable feature,
though, but on the other hand an entirely new default CD-ROM filing
system for AmigaOS might be even more desirable.
Christian Wasner (Christia...@hamburg.netsurf.de) wrote:
>Heinz Wrobel (he...@hwg.muc.de) wrote about Re: Easy way to get file size?:
>>to work on large files, use Examine(). Note that Examine() won't
>>necessarily reflect the current size for opened writable files.
>>While changing a file, Seek on the fh is reliable.
>This also counts for Seek(). If multiple processes opened the file
>non-exclusively, its length may increase immediately after Seek()ing
>to its end. However, common sense tells me that it may not become
>smaller, at least with Amiga OS.
Huh? AFAIK non-exclusive locks may not change/write to the file, therefore
it won't increase/decrease in size. Only exclusive locks are allowed to
change a file, but then you can't lock the file non-exclusively and
therefore can't Seek() or Examine() it unless you are the exclusive owner.
--
Andreas E. Bombe <andrea...@munich.netsurf.de>
http://home.pages.de/~andreas.bombe/
PGP key fingerprint: 13 6B BC 15 36 B8 B7 7A 20 05 58 E8 6F AA F8 ED
--key available from homepage and on request (no valid key on servers)
: <using Seek()>
:
: Seek()ing/fseek()ing to EOF takes much time because all file extension
: blocks must be read, so there may be much (and possibly lengthy) drive
well, "much". If you want to write a filebrowser, then you need
the optimal possible way.
If you just wanna know filelen to know how much to allocmem() and
then load the file, time is neglectible.
2 seeks is one "tac" on floppy drive ;) oh, I forgot it's a open() and 2 seek
(I guess the close cost nothing here), unless you do it a bit less generic,
open
len=seekseek
allocmem(len)
read(len)
close
but, even
getfilelen=openseekseekclose
allocmem
open
read
close
is aceptable even on floppy.
: activity. Better Lock() the file and Examine() it or use ExamineFH().
Examine sounds to me like doing at least a "tac", to :)
: However, this technique is not possible with ANSI functions.
: >> In that case ExamineFH() might be an even better choice.
:
: >But not all FileSystems support the dos packet for this function!
:
: So what ? Upgrade those filesysystems or throw them away if there is
: none. Kickstart 2.0 is out for some years now, at last.
:
If I can do something V1.2 without disadvantage, I do it V1.2,
flame me but logic is on my side ;)
2x seek is negelctible overhead if you intend to load the file.
> int file_size(unsigned char *fname)
>
> {
> __aligned struct FileInfoBlock info;
I'd rather use AllocDosObject(DOS_FIB,NULL)/FreeDosObject(DOS_FIB,info) here.
Yeah, I know that's not obligatory - it's just like using FindTask(NULL)
instead of reading ExecBase->ThisTask. The latter is not explicitely
forbidden but the former is provided by the OS so we should use it.
bye!
Matthias
--
Our temple is sound, we fight our battles with music, drums like thunder,
cymbals like lightning, banks of electronic equipment like nuclear missiles
of sound. We have guitars instead of tommy-guns. [Wally Hope]
Andreas E. Bombe (andrea...@munich.netsurf.de) wrote about Re: Easy way to get file size?:
AEB> Huh? AFAIK non-exclusive locks may not change/write to the file, therefo
AEB> it won't increase/decrease in size. Only exclusive locks are allowed to
AEB> change a file, but then you can't lock the file non-exclusively and
AEB> therefore can't Seek() or Examine() it unless you are the exclusive owne
Wrong. You can Open(file,MODE_OLDFILE) a file and write beyond its
end. File size can be decreased by a 2.0+ dospacket (if the
filesystem supports this packet).
Juergen "Rally" Fischer (fisc...@Informatik.TU-Muenchen.DE) wrote about Re: Easy way to get file size?:
J"F> Christian Wasner (Christia...@hamburg.netsurf.de) wrote:
J"F> If I can do something V1.2 without disadvantage, I do it V1.2,
J"F> flame me but logic is on my side ;)
J"F> 2x seek is negelctible overhead if you intend to load the file.
For 1.1 support use Lock() and Examine().
Juergen "Rally" Fischer (fisc...@Informatik.TU-Muenchen.DE) wrote about Re: Easy way to get file size?:
J"F> Christian Wasner (Christia...@hamburg.netsurf.de) wrote:
J"F>: <using Seek()>
J"F>:
J"F>: Seek()ing/fseek()ing to EOF takes much time because all file extension
J"F>: blocks must be read, so there may be much (and possibly lengthy) drive
J"F> well, "much". If you want to write a filebrowser, then you need
J"F> the optimal possible way.
It always depends on what you want to write. If you want to write a
"list" program (like the shell command), it's not a clever idea to
Seek() to the end of each file. It shouldn't be too difficult to use
Lock() and Examine() if you don't have to rely on ANSI functions.
J"F> Examine sounds to me like doing at least a "tac", to :)
No. Examine() accesses the first block of a file (which is loaded
anyway) and nothing else.
: It always depends on what you want to write. If you want to write a
: "list" program (like the shell command), it's not a clever idea to
yep.
: Seek() to the end of each file. It shouldn't be too difficult to use
: Lock() and Examine() if you don't have to rely on ANSI functions.
:
: J"F> Examine sounds to me like doing at least a "tac", to :)
:
: No. Examine() accesses the first block of a file (which is loaded
running "list" on A500 sometimes each file displayed was a "tac".
I guess it depends.
: anyway) and nothing else.
Thanks, my routine does already well for the purpose ;)
I wrote flen() with ANSI calls.
Then I wrote an own seek/ftell pair using Seek() so I
can compile it to run without alien code used.
Why dont do this:
length:=FileLength(filename)
Ist`s a dos-function :-)
PS: Don`t Flame if i`m not right :-)
--
________ ______
/__ __\ __________()_____ _\ / /\ turr...@starbase.inka.de
\ //\/\\ _/\ _//\\ __//_\\ \/ \ THE DARK FRONTIER
\//____\\/ \/ /__\\_//___\\/\_____\ Softwareentwicklung PD+Share
On 29-Sep-96 04:46:58 Juergen "Rally" Fischer wrote about Re: Easy way to get
file size? in comp.sys.amiga.programmer:
>I wrote flen() with ANSI calls.
>Then I wrote an own seek/ftell pair using Seek() so I
>can compile it to run without alien code used.
Ever checked that fcntl() command, which is Ansi-C and is quite similar to
AmigaDos Execute() ?
--
<> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
_ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
\X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
In a random sampling of GoldED users, 100% said that they'd rather
use GoldED than be publically flogged, eaten alive by pirhanas, OR
watch SeaQuest DSV.
fcntl is not a standard ANSI C function.
Volker
On 01-Oct-96 04:53:33 Volker Barthelmann wrote about Re: Easy way to get file
size? in comp.sys.amiga.programmer:
>fcntl is not a standard ANSI C function.
Okay, my apologizes for this mistake, I`d a look into my Unix-C book, and
didn`t saw it`s not Ansi.
--
<> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
_ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
\X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
MODEM: Monumentally Overpriced Data Eating Machine
> Ever checked that fcntl() command, which is Ansi-C and is quite similar to
> AmigaDos Execute() ?
fcntl() is not Ansi-C, it is Unix.
On 29-Sep-96 15:44:21 Mathias Grundler wrote about Re: Easy way to get file
size? in comp.sys.amiga.programmer:
> length:=FileLength(filename)
>Ist`s a dos-function :-)
This function is neither in dos.library or amiga.lib, nor is it ANSI or Unix-
C. Where did you get that?
--
<> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
_ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
\X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
Shoot anything that moves, and if it doesn`t move, shoot it anyway!
: > length:=FileLength(filename)
: >Ist`s a dos-function :-)
: This function is neither in dos.library or amiga.lib, nor is it ANSI or Unix-
: C. Where did you get that?
It's an internal function of E and not a dos function. I don't know wether
there are other languages with this function built-in.
Hope this helps,
--
Jaco Schoonen
(ja...@stack.urc.tue.nl)
> Why dont do this:
>
> length:=FileLength(filename)
>
> Ist`s a dos-function :-)
MS-dos ???
-----
Andreas Winkelmann
E-Mail : an...@art-line.de -- MicroDot V1.11beta29
On 03-Oct-96 15:36:43 Jaco Schoonen wrote about Re: Easy way to get file size?
in comp.sys.amiga.programmer:
>It's an internal function of E and not a dos function. I don't know wether
>there are other languages with this function built-in.
No other, as it`s quite redundant. Examine() provides far more informations
while not being really more difficult to handle.
--
<> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
_ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
\X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
If you are being punished, it's done with a deadly weapon.
You must be thinking of something else. fcntl() is a unix function that can
be used to modify the behaviour of a file descriptor (eg make it nonblocking).
It is nothing like Execute() and I can't imagine what you could use it for
with regards to calculating file lengths.
--
Steve Hodge
s...@cs.waikato.ac.nz
Computer Science Dept, University of Waikato,
Hamilton, New Zealand
On 04-Oct-96 04:08:07 Stephen B Hodge wrote about Re: Easy way to get file
size? in comp.sys.amiga.programmer:
>You must be thinking of something else. fcntl() is a unix function that can
>be used to modify the behaviour of a file descriptor (eg make it
Sorry, my mistake. I looked it up in my unix-c-book, and there is a mistake.
The function I was talking about was stat(), which allows you to get via
st_size the filesize.
--
<> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
_ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
\X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
Q: How many IBM cpu's does it take to do a logical right shift?
A: 33.1 to hold the bits and 32 to push the register.
: No other, as it`s quite redundant. Examine() provides far more informations
: while not being really more difficult to handle.
I don't agree on that one. The E-command Filelength just takes a string as
argument.
To use Examine, you have to Lock() the file, allocate a fileinfoblock, call
examine and unlock again.
If you just need the filelength I know which I prefer...
--
Jaco Schoonen
(ja...@stack.urc.tue.nl)
> > I wrote flen() with ANSI calls.
> > Then I wrote an own seek/ftell pair using Seek() so I
> > can compile it to run without alien code used.
My solution also.
> Ever checked that fcntl() command, which is Ansi-C and is quite similar to
> AmigaDos Execute() ?
fcntl()? What the?
fx: rummages around on paper laden desk till uncovers ANSI C bible...
There's no fcntl() function in ANSI C, matey.
The Yum Yum Boy...
----mailto:toby.d...@ebo.mts.dec.com
"you're such a sensitive boy that sometimes i just wanna slap you really
hard."
- Aimee Lortskell
----http://bes161.ebo.dec.com/support/project/YumYumBoy/index.html
Try this. Now you have the best of both worlds ;)
/* be sure to include dos/dos.h and clib/dos_protos.h */
ULONG FileLength(STRPTR filename)
{
int i;
BPTR lock;
struct FileInfoBlock fib;
if (fh = Lock(filename, ACCESS_READ))
{
Examine(lock, &fib);
UnLock(lock);
}
/* if compiling for windows 95, be sure
** to waste some time before returning ;)
*/
#ifdef WINDOWS_95
for (i = 0; i < 20000; i++)
;
#endif
return(fib->fib_Size);
}
I am not responsible for any discomfort, damages, loss of data, or fire
hazards this post may have caused either directly or indirectly.
On 05-Oct-96 00:44:39 Jaco Schoonen wrote about Re: Easy way to get file size?
in comp.sys.amiga.programmer:
>To use Examine, you have to Lock() the file, allocate a fileinfoblock, call
>examine and unlock again.
>If you just need the filelength I know which I prefer...
So please tell me what FileLength() internally does. It can`t do anything
else... but if you use E as language, feel free to use it :)
--
<> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
_ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
\X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
If it sucks, it must be Microsoft!
JS> I don't agree on that one. The E-command Filelength just takes a string as
JS> argument.
Lock(name,accessMode)
Where is your problem ? ;-)
JS> To use Examine, you have to Lock() the file, allocate a fileinfoblock, call
JS> examine and unlock again.
You are talking about 30 secs. of work, not more. And you'll get lots more
of informations (creation date etc.).
JS> If you just need the filelength I know which I prefer...
Yes but with Lock() you can get sure nothing happens to the file ;-)
Are you sure the e-command *Filelenght* locks it, too ??
What happens if another program has a ACCESS_WRITE to that file ?
Regards,
Nils
jaiden (jai...@aros.net) wrote about Re: Easy way to get file size?:
j> Jaco Schoonen wrote:
j> /* be sure to include dos/dos.h and clib/dos_protos.h */
j> ULONG FileLength(STRPTR filename)
j> {
j> int i;
j> BPTR lock;
j> struct FileInfoBlock fib;
j> if (fh = Lock(filename, ACCESS_READ))
j> {
j> Examine(lock, &fib);
Tsk, tsk... You shouldn't pass &fib to Examine() because fib may not
be longword aligned when allocating it from the stack. Use
AllocDosObject() (or AllocMem() if you want to ensure 1.3
compatibility).
j> ...
j> return(fib->fib_Size);
fib.fib_Size is correct, of course... a typo, I assume. In addition,
you don't report a Lock() failure.
j> }
> On 29-Sep-96 15:44:21 Mathias Grundler wrote about Re: Easy way to get file
> size? in comp.sys.amiga.programmer:
> > length:=FileLength(filename)
> >Ist`s a dos-function :-)
>
> This function is neither in dos.library or amiga.lib, nor is it ANSI or Unix-
> C. Where did you get that?
It's a E Function...
>
> --
> <> _ USR - The *ONLY* Choice in Data Communications! <+> PGP C691F125
> _ // Visit the M$-HateLibrary @ | MSN is prohibited from redis-
> \X/ http://134.95.214.191/~gzenz/ | tributing this in any form!
>
> Shoot anything that moves, and if it doesn`t move, shoot it anyway!
>
ciao
Pablo / Retire ^ LSD | pa...@ag-trek.rhein-ruhr.de | coder!=)0d3r
Not only assuming that a future DOS would be able to do magic
things with a FIB, you should think hard about using
AllocDosObject(DOS_FIB, NULL) instead. __aligned isn't exactly
portable anyway.
--
Heinz Wrobel Private Mail: he...@hwg.muc.de
My private FAX: +49 89 850 51 25, I prefer email