Created
May 10, 2017 14:17
-
-
Save jakekara/80596044f1de596a4ba37449593d305b to your computer and use it in GitHub Desktop.
get a file's size in bytes two ways, using lseek and stat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * determine a file's size with stat | |
| */ | |
| #include <sys/stat.h> /* for stat */ | |
| #include <stdio.h> /* for printf */ | |
| int main(int ac, char *av[]) | |
| { | |
| if ( ac < 2 ) return 0; | |
| struct stat stbuf; | |
| stat( av[1], &stbuf); /* 1 syscall */ | |
| printf ("%lld\n", stbuf.st_size); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment