Article View: comp.sys.amiga.tech
Article #4640Re: Wanted: Filelength() function
From: markv
Date: Tue, 31 Jul 1990 19:25
Date: Tue, 31 Jul 1990 19:25
42 lines
1961 bytes
1961 bytes
> I don't think there's a function that returns the filelength of a file, with
> AmigaDOS.But I need an equivalent...how do you determine the length of a file
> given onlythe file handle (eg from an Open)? There must be a way to find the
> associated file lock, as one is created when the file is opened (shared /
> exclusive)...right? Then you can Examine the FileInfoBlock and get the file's
> length from the fibSize field.
>
> ie size_t filelength(int handle)
>
>Iwant a function that doesn't require knowing the filename...or do I need 2.0?
>
> Thanks.
If you use C stream handles (not Amiga ones) just try the following function:
#include <stdio.h>
size_t filelength(FILE *FooFile)
{
pos_t save_pos;
size_t temp;
/*
** fseek() and ftell() do all the work. fgetpos() and fsetpos() insure
** that we leave the file the way we got it.
*/
save_pos = fgetpos(FooFile);
fseek(FooFile, 0, SEEK_END);
temp = ftell(FooFile);
fsetpos(FooFile, save_pos);
return(temp);
}
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum Only... \ Good Cheer !!!
Academic Computing Services /// \___________________________
University of Kansas /// /| __ _
Bix: markgood \\\ /// /__| |\/| | | _ /_\ makes it
Bitnet: MARKV@UKANVAX \/\/ / | | | | |__| / \ possible...
Internet: markv@kuhub.cc.ukans.edu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Technical Details
Message-ID:
<25061.26b594ea@kuhub.cc.ukans.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!kuhub.cc.ukans.edu!markvReferences:
<2671@mindlink.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!kuhub.cc.ukans.edu!markv From: markv@kuhub.cc.ukans.edu Newsgroups: comp.sys.amiga.tech Subject: Re: Wanted: Filelength() function Message-ID: <25061.26b594ea@kuhub.cc.ukans.edu> Date: 31 Jul 90 19:25:46 GMT References: <2671@mindlink.UUCP> Organization: University of Kansas Academic Computing Services Lines: 42