Syntax
#include <io.h> long _filelength(int handle);Description
A return value of -1L indicates an error, and errno is set to one of the following values: compact break=fit.
Value
This example opens a file and tries to determine the current length of the file using _filelength.
#include <io.h>#include <stdio.h> #include <stdlib.h> #include <fcntl.h> int main(void) { long length; int fh; printf("\nCreating sample.dat.\n"); system("echo Sample Program > sample.dat"); if (-1 == (fh = open("sample.dat", O_RDWR|O_APPEND))) { printf("Unable to open sample.dat.\n"); return EXIT_FAILURE; } if (-1 == (length = _filelength(fh))) { printf("Unable to determine length of sample.dat.\n"); return EXIT_FAILURE; } printf("Current length of sample.dat is %d.\n", length); close(fh); return 0; /**************************************************************************** The output should be: Creating sample.dat. Current length of sample.dat is 17. ****************************************************************************/ }Related Information