filelength
Go Up to io.h Index
Header File
io.h
Category
Input/output Routines
Prototype
long filelength(int handle);
Description
Gets file size in bytes.
filelength returns the length (in bytes) of the file associated with handle.
Return 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 |
Example
#include <string.h> #include <stdio.h> #include <fcntl.h> #include <io.h> int main(void) { int handle; char buf[11] = "0123456789"; /* create a file containing 10 bytes */ handle = open("DUMMY.FIL", O_CREAT); 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; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ |
---|---|---|---|
+ |