Skip to content

Instantly share code, notes, and snippets.

@jakekara
Created May 10, 2017 14:17
Show Gist options
  • Select an option

  • Save jakekara/80596044f1de596a4ba37449593d305b to your computer and use it in GitHub Desktop.

Select an option

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
/*
* 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