Name
filelength - Returns length of target file.
Syntax
#include <io.h>
long filelength(handle)
int handle;
Description
The filelength function returns the length, in bytes, of
target file handle.
Return Value
The filelength function returns the file length in bytes. A
return value of -1L indicates an error, and an invalid
handle sets errno to EBADF.
See Also
chsize(S), fileno(S), fstat(DOS), stat(DOS)
Example
#include <io.h> #include <stdio.h>
FILE *stream; long length;
main()
{
stream = fopen("data","r");
/* Get length or -1L if function fails: */
length = filelength(fileno(stream));
/* If function failed... */
if (length == -1L)
printf("filelength failed");
else
printf( "file length is %ld\n", length );
}
This program opens a file named data, using filelength to
determine its length. If filelength fails, it returns -1L
and the program displays a failure message. Otherwise, the
program displays the length of data.
(printed 6/18/89)