filelength
raw OCR
Gets file size in bytes.
Defined in header <io.h>
Syntax
#include <io.h>
long filelength(int handle);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
filelength returns the length (in bytes) of the file associated with handle.
Retum value
On success, filelength returns a long value, the file length in bytes. On error, it returns -1 and the global variable errno is set to
EBADF Bad file number
See also
Example
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <string.h>
int main (void)
{
int handle;
char buf[ll] = "0123456789";
/* create a file containing 10 bytes */
handle = open("DUfflY.FIL", 0_RDWRI0_CREATI0_TRUNC, S_IREAD|S_IWRITE)
write(handle, buf, strlen(buf ));
/* display the size of the file */
printf("file length in bytes: %ld\n", filelength(handle));
/* close the file */
close(handle) ;
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/io.h/filelength/
· short form /3.1/filelength/