If you have the file descriptor fstat() returns a stat structure which contain the file size.
#include
#include
#include
// fd = fileno(f); //if you have a stream (e.g. from fopen), not a file descriptor.
struct stat buf;
fstat(fd, &buf);
off_t size = buf.st_size;