The stat() function call returns -1 on error. Are you checking the return code?
Then finding what
errno references to produce a meaningful error message?
perror() will do that for you.
lstat() works on symlinks only -- you aren't calling lstat? Even though your error message says so.
These are the two calls you should be using. stat() is a much more likely choice.
Code:
int stat(const char *path, struct stat *buf);
int fstat(int filesdes, struct stat *buf);