stat() is enough here, no? Otherwise you need to close fp afterwards or you get a file descriptor leak.