I know about fseek but as that sets the 'cursor" to the very end of the file, I'm guessing that does actually read through all of the file.
It does not. For linux, it uses the llseek file operation which will check that the operand is in-range and only set this file descriptor's offset if that check passes. It may need to access the underlying device in order to walk some of the filesystem's data structures, though. But it won't "read" the file in that the operation shouldn't become significantly more expensive with larger files. Technically, that's filesystem-dependent behavior though.
For posix, you could do the following:
get_filesize.h:
#include <stdint.h> uint64_t get_size(const char *filename);
get_filesize_posix.c:
#include "get_filesize.h" #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> uint64_t get_size(const char *filename) { struct stat s; int ret = stat(filename, &s); if (ret != 0) perror("stat"); return (uint64_t) s.st_size; }
stat, which would read the file's metadata, and include size info.