Skip to content

Instantly share code, notes, and snippets.

@sriramster
Last active August 29, 2015 14:01
Show Gist options
  • Save sriramster/1e82fa266e683d3acf42 to your computer and use it in GitHub Desktop.
Save sriramster/1e82fa266e683d3acf42 to your computer and use it in GitHub Desktop.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#define usage() {printf("\n Usage %s file_name", argv[0]);}
int main(int argc, char *argv[])
{
if (argc < 2) {
usage();
exit(-1);
}
int fd = open(argv[1], O_RDONLY);
struct stat buf;
if(fd < 0) {
perror("open error");
exit(-1);
}
if(fstat(fd, &buf) < 0) {
perror("stat error");
exit(-1);
}
printf("\n Size %ld", (long)buf.st_size);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment